Skip to content

Commit bd21510

Browse files
committed
1 parent aebba48 commit bd21510

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎tests/PHPStan/Analyser/NoBleedingEdgeTypeInferenceTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static function dataAsserts(): iterable
2121
yield from self::gatherAssertTypes(__DIR__ . '/nsrt/bug-15820.php');
2222
yield from self::gatherAssertTypes(__DIR__ . '/nsrt/bug-15860.php');
2323
yield from self::gatherAssertTypes(__DIR__ . '/nsrt/bug-15869.php');
24+
yield from self::gatherAssertTypes(__DIR__ . '/nsrt/bug-15870.php');
2425
}
2526

2627
/**
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug15870;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param list<list<string>> $messages
9+
* @param list<string> $parts
10+
*/
11+
function parse(string $name, array $messages, array $parts, string $line, int $t): void
12+
{
13+
$data['header'][0]['name'] = $name;
14+
for ($m = 0; $m < count($messages); $m++) {
15+
$data['message'][$m]['header']['_pointer'] = 'header[0][id]';
16+
for ($l = 0; $l < count($messages[$m]); $l++) {
17+
switch ($messages[$m][$l]) {
18+
case 'a':
19+
$data['message'][$m]['reference'] = trim($line);
20+
$data['message'][$m]['account'] = trim($line);
21+
case 'b':
22+
$data['message'][$m]['number'] = trim($parts[0]);
23+
$data['message'][$m]['sequence'] = trim($parts[1] ?? '');
24+
case 'c':
25+
if (!isset($data['message'][$m]['startSign'])) {
26+
$data['message'][$m]['startSign'] = trim($line);
27+
$data['message'][$m]['startDate'] = trim($line);
28+
$data['message'][$m]['startCurrency'] = trim($line);
29+
$data['message'][$m]['startBalance'] = trim($line);
30+
}
31+
assertType("array{header: array{array{name: string}}, message: non-empty-array<int<0, max>, array{header?: array{_pointer: 'header[0][id]'}, endBalance?: string, startSign?: string, startDate?: string, startCurrency?: string, startBalance?: string, number?: string, sequence?: string, reference?: string, account?: string}>, transaction?: non-empty-array<int, array{description: string}>}", $data);
32+
$data['transaction'][$t]['description'] .= trim($line);
33+
case 'd':
34+
$data['message'][$m]['endBalance'] = trim($line);
35+
}
36+
}
37+
assertType("array{header: array{array{name: string}}, message: non-empty-array<int<0, max>, array{header?: array{_pointer: 'header[0][id]'}, endBalance?: string, startSign?: string, startDate?: string, startCurrency?: string, startBalance?: string, number?: string, sequence?: string, reference?: string, account?: string}>, transaction?: non-empty-array<int, array{description: string}>}", $data);
38+
foreach ($data['transaction'] as $transaction) {
39+
}
40+
}
41+
}

‎tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,20 @@ public function testBug15869(): void
14261426
]);
14271427
}
14281428

1429+
public function testBug15870(): void
1430+
{
1431+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-15870.php'], [
1432+
[
1433+
'Offset \'transaction\' might not exist on array{header: array{array{name: string}}, message: non-empty-array<int<0, max>, array{header?: array{_pointer: \'header[0][id]\'}, endBalance?: string, startSign?: string, startDate?: string, startCurrency?: string, startBalance?: string, number?: string, sequence?: string, ...}>, transaction?: non-empty-array<int, array{description: string}>}.',
1434+
32,
1435+
],
1436+
[
1437+
'Offset \'transaction\' might not exist on array{header: array{array{name: string}}, message: non-empty-array<int<0, max>, array{header?: array{_pointer: \'header[0][id]\'}, endBalance?: string, startSign?: string, startDate?: string, startCurrency?: string, startBalance?: string, number?: string, sequence?: string, ...}>, transaction?: non-empty-array<int, array{description: string}>}.',
1438+
38,
1439+
],
1440+
]);
1441+
}
1442+
14291443
public static function dataUnsealedArrayShapes(): iterable
14301444
{
14311445
foreach ([false, true] as $reportPossiblyNonexistentGeneralArrayOffset) {

0 commit comments

Comments
 (0)