Skip to content

Commit 2165958

Browse files
Fix
1 parent 71f3e51 commit 2165958

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/Rules/Arrays/NonexistentOffsetInArrayDimFetchCheck.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPStan\Type\ErrorType;
1515
use PHPStan\Type\Type;
1616
use PHPStan\Type\TypeUtils;
17-
use PHPStan\Type\UnionType;
1817
use PHPStan\Type\VerbosityLevel;
1918
use function count;
2019
use function sprintf;
@@ -95,17 +94,15 @@ public function check(
9594
$report = true;
9695
break;
9796
}
98-
if ($dimType instanceof UnionType) {
99-
foreach ($dimType->getTypes() as $subDimType) {
100-
if ($innerType->hasOffsetValueType($subDimType)->no()) {
101-
$report = true;
102-
break 2;
103-
}
104-
}
105-
continue;
97+
if ($dimType instanceof BenevolentUnionType) {
98+
$flattenedInnerTypes = [$dimType];
99+
} else {
100+
$flattenedInnerTypes = TypeUtils::flattenTypes($dimType);
106101
}
107-
foreach (TypeUtils::flattenTypes($dimType) as $innerDimType) {
108-
if ($innerType->hasOffsetValueType($innerDimType)->no()) {
102+
foreach ($flattenedInnerTypes as $innerDimType) {
103+
if (
104+
$innerType->hasOffsetValueType($innerDimType)->no()
105+
) {
109106
$report = true;
110107
break 2;
111108
}

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function testRule(): void
132132
312,
133133
],
134134
[
135-
' Offset int|null might not exist on array<string, string>.',
135+
'Offset int|null might not exist on array<string, string>.',
136136
314,
137137
],
138138
[
@@ -193,10 +193,6 @@ public function testStrings(): void
193193
'Offset 12.34 does not exist on \'foo\'.',
194194
13,
195195
],
196-
[
197-
"Offset int|object might not exist on 'foo'.",
198-
16,
199-
],
200196
[
201197
'Offset \'foo\' might not exist on array|string.',
202198
24,
@@ -205,10 +201,6 @@ public function testStrings(): void
205201
'Offset 12.34 might not exist on array|string.',
206202
28,
207203
],
208-
[
209-
'Offset int|object might not exist on array|string.',
210-
32,
211-
],
212204
]);
213205
}
214206

0 commit comments

Comments
 (0)