Skip to content

Commit a2621b7

Browse files
committed
assert all branches
1 parent cd2f4af commit a2621b7

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

tests/PHPStan/Analyser/nsrt/array-find-key-existing.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ function arrayFindKeyNotNull(array $list, string $s): void
1414
$key = array_find_key($list, fn (string $v) => $v === $s);
1515
if ($key !== null) {
1616
assertType('non-empty-list<string>', $list);
17+
assertType('int<0, max>', $key);
1718
assertType('string', $list[$key]);
19+
} else {
20+
assertType('array{}', $list);
21+
assertType('null', $key);
22+
assertType('*ERROR*', $list[$key]);
1823
}
24+
assertType('list<string>', $list);
25+
assertType('int<0, max>|null', $key);
26+
assertType('string', $list[$key]);
1927
}
2028

2129
/**

tests/PHPStan/Analyser/nsrt/array-search-existing.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,18 @@ function arraySearchStrictNarrowsToNeedle(array $arr, int $needle): void
4545
{
4646
$key = array_search($needle, $arr, true);
4747
if ($key !== false) {
48+
assertType('non-empty-array<string, int|string>', $arr);
49+
assertType('string', $key);
4850
assertType('int', $arr[$key]);
51+
} else {
52+
assertType('array<string, int|string>', $arr);
53+
assertType('false', $key);
54+
assertType('*ERROR*', $arr[$key]);
4955
}
56+
assertType('array<string, int|string>', $arr);
57+
assertType('string|false', $key);
58+
assertType('int|string', $arr[$key]);
59+
5060
}
5161

5262
/**

0 commit comments

Comments
 (0)