Skip to content

Commit 09d59ca

Browse files
phpstan-botclaude
authored andcommitted
Reference NSRT test files from NonexistentOffsetInArrayDimFetchRuleTest instead of duplicating
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ca44a17 commit 09d59ca

4 files changed

Lines changed: 23 additions & 75 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,14 @@ function arrayFindKeyStringKey(array $map): void
2828
assertType('int', $map[$key]);
2929
}
3030
}
31+
32+
/**
33+
* @param list<string> $list
34+
*/
35+
function arrayFindKeyReversedComparison(array $list, string $s): void
36+
{
37+
$key = array_find_key($list, fn (string $v) => $v === $s);
38+
if (null !== $key) {
39+
assertType('string', $list[$key]);
40+
}
41+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ function arraySearchStringKey(array $map, int $needle): void
3030
/**
3131
* @param list<string> $list
3232
*/
33-
function arraySearchDeepWrite(array $list, string $s): void
33+
function arraySearchReversedComparison(array $list, string $s): void
3434
{
3535
$key = array_search($s, $list);
36-
if ($key !== false) {
36+
if (false !== $key) {
3737
assertType('string', $list[$key]);
3838
}
3939
}

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,11 +1305,19 @@ public function testBug11218(): void
13051305
$this->analyse([__DIR__ . '/data/bug-11218.php'], []);
13061306
}
13071307

1308-
public function testBug14537(): void
1308+
public function testArraySearchExisting(): void
13091309
{
13101310
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
13111311

1312-
$this->analyse([__DIR__ . '/data/bug-14537.php'], []);
1312+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/array-search-existing.php'], []);
1313+
}
1314+
1315+
#[RequiresPhp('>= 8.4.0')]
1316+
public function testArrayFindKeyExisting(): void
1317+
{
1318+
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
1319+
1320+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/array-find-key-existing.php'], []);
13131321
}
13141322

13151323
}

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

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)