Skip to content

Commit 6409fde

Browse files
committed
address feedback
1 parent ec98616 commit 6409fde

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

src/Type/MixedType.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ public function setExistingOffsetValueType(Type $offsetType, Type $valueType): T
172172
$types = [
173173
new ArrayType(new MixedType(), new MixedType()),
174174
new ObjectType(ArrayAccess::class),
175-
new NullType(),
176175
];
177-
if ($offsetType->isInteger()->yes()) {
176+
if (!$offsetType->isInteger()->no()) {
178177
$types[] = new StringType();
179178
}
180179
return TypeCombinator::union(...$types);

tests/PHPStan/Analyser/nsrt/bug-13270a.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,33 @@ public function test(array $data): void
2020
}
2121
}
2222

23-
/*
24-
public function doFoo(mixed $mixed, int $i): void
23+
public function doFoo(
24+
mixed $mixed,
25+
mixed $mixed2,
26+
mixed $mixed3,
27+
mixed $mixed4,
28+
int $i,
29+
int $i2,
30+
string|int $stringOrInt
31+
): void
2532
{
2633
$mixed[$i]['a'] = true;
27-
dumpType($mixed);
34+
assertType('mixed', $mixed);
35+
36+
$mixed2[$stringOrInt]['a'] = true;
37+
assertType('mixed', $mixed2);
38+
39+
$mixed3[$i][$stringOrInt] = true;
40+
assertType('mixed', $mixed3);
41+
42+
$mixed4['a'][$stringOrInt] = true;
43+
assertType('mixed', $mixed4);
44+
45+
$null = null;
46+
$null[$i]['a'] = true;
47+
assertType('non-empty-array<int, array{a: true}>', $null);
48+
49+
$i2['a'] = true;
50+
assertType('*ERROR*', $i2);
2851
}
29-
*/
3052
}

tests/PHPStan/Analyser/nsrt/composer-array-bug.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ public function doFoo(): void
1919
foreach ($this->config['authors'] as $key => $author) {
2020
if (!is_array($author)) {
2121
$this->errors[] = 'authors.'.$key.' : should be an array, '.gettype($author).' given';
22-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
22+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
2323
unset($this->config['authors'][$key]);
24-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
24+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
2525
continue;
2626
}
27-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
27+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
2828
foreach (['homepage', 'email', 'name', 'role'] as $authorData) {
2929
if (isset($author[$authorData]) && !is_string($author[$authorData])) {
3030
$this->errors[] = 'authors.'.$key.'.'.$authorData.' : invalid value, must be a string';
3131
unset($this->config['authors'][$key][$authorData]);
3232
}
3333
}
3434
if (isset($author['homepage'])) {
35-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
35+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
3636
unset($this->config['authors'][$key]['homepage']);
37-
assertType("array|ArrayAccess|null", $this->config['authors']);
37+
assertType("array|ArrayAccess|string", $this->config['authors']);
3838
}
3939
if (isset($author['email']) && !filter_var($author['email'], FILTER_VALIDATE_EMAIL)) {
4040
unset($this->config['authors'][$key]['email']);
@@ -44,8 +44,8 @@ public function doFoo(): void
4444
}
4545
}
4646

47-
assertType("non-empty-array&hasOffsetValue('authors', mixed~(0|0.0|''|'0'|false))", $this->config);
48-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
47+
assertType("non-empty-array&hasOffsetValue('authors', mixed~(0|0.0|false|null))", $this->config);
48+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
4949

5050
if (empty($this->config['authors'])) {
5151
unset($this->config['authors']);

tests/PHPStan/Analyser/nsrt/composer-non-empty-array-after-unset.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public function doFoo()
1515
if (!empty($this->config['authors'])) {
1616
assertType("mixed~(0|0.0|''|'0'|array{}|false|null)", $this->config['authors']);
1717
foreach ($this->config['authors'] as $key => $author) {
18-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
18+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
1919
if (!is_array($author)) {
2020
unset($this->config['authors'][$key]);
21-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
21+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
2222
continue;
2323
}
2424
foreach (['homepage', 'email', 'name', 'role'] as $authorData) {
@@ -33,13 +33,13 @@ public function doFoo()
3333
unset($this->config['authors'][$key]['email']);
3434
}
3535
if (empty($this->config['authors'][$key])) {
36-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
36+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
3737
unset($this->config['authors'][$key]);
38-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
38+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
3939
}
40-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
40+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
4141
}
42-
assertType("mixed~(0|0.0|''|'0'|false)", $this->config['authors']);
42+
assertType("mixed~(0|0.0|false|null)", $this->config['authors']);
4343
}
4444
}
4545

0 commit comments

Comments
 (0)