Skip to content

Commit c42f502

Browse files
committed
more tests
1 parent e940c0d commit c42f502

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,9 +1194,13 @@ public function testBug14234(): void
11941194
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
11951195

11961196
$this->analyse([__DIR__ . '/data/bug-14234.php'], [
1197+
[
1198+
'Offset int<2, max> might not exist on non-empty-array<int<0, max>, string>.',
1199+
49,
1200+
],
11971201
[
11981202
'Offset int<0, max> might not exist on array.',
1199-
48,
1203+
60,
12001204
],
12011205
]);
12021206
}

tests/PHPStan/Rules/Arrays/data/bug-14234.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ function getShortenedPath3(string $identifier): string
4040
return implode("/", $parts);
4141
}
4242

43-
function getShortenedPath4(array $parts): string
43+
function getShortenedPath4(string $identifier): string
44+
{
45+
$parts = explode('/', $identifier);
46+
assertType('non-empty-list<string>', $parts);
47+
48+
for ($i = 2; $i < count($parts) - 4; $i++) {
49+
$parts[$i] = substr($parts[$i], 0, 1); // should not error
50+
}
51+
52+
return implode("/", $parts);
53+
}
54+
55+
function errorOnRegularError(array $parts): string
4456
{
4557
assertType('array', $parts);
4658

0 commit comments

Comments
 (0)