Skip to content

Commit 2aed77d

Browse files
committed
more tests
1 parent f02b5c1 commit 2aed77d

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,10 @@ public function testBug13770(): void
11901190
'Offset int<0, max> might not exist on list<int>.',
11911191
139,
11921192
],
1193+
[
1194+
'Offset int<0, max> might not exist on array.',
1195+
177,
1196+
],
11931197
]);
11941198
}
11951199

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,29 @@ public function ZeroOrMoreIntLessThanOrEqualCountMinusOne(array $array, int $ind
154154

155155
return 0;
156156
}
157+
158+
/**
159+
* @param list<int> $array
160+
* @param 0|positive-int $index
161+
*/
162+
public function ZeroOrMoreIntLessThanOrEqualCountMinusFive(array $array, int $index): int
163+
{
164+
if ($index <= count($array) - 5) {
165+
return $array[$index];
166+
}
167+
168+
return 0;
169+
}
170+
171+
/**
172+
* @param 0|positive-int $index
173+
*/
174+
public function errorsBecauseNotList(array $array, int $index): int
175+
{
176+
if ($index <= count($array) - 5) {
177+
return $array[$index];
178+
}
179+
180+
return 0;
181+
}
157182
}

0 commit comments

Comments
 (0)