Skip to content

Commit 86db4da

Browse files
phpstan-botclaude
andcommitted
Add NullCoalesceRule test for phpstan/phpstan#13623
The original bug report was about a false positive "Offset ... on left side of ??= always exists and is not nullable." error, so this adds a non-regression test in NullCoalesceRuleTest. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 84e6766 commit 86db4da

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,9 @@ public function testBug13921(): void
377377
]);
378378
}
379379

380+
public function testBug13623(): void
381+
{
382+
$this->analyse([__DIR__ . '/data/bug-13623.php'], []);
383+
}
384+
380385
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug13623Rule;
6+
7+
function (array $results): void {
8+
$customers = [];
9+
10+
foreach ($results as $row) {
11+
$customers[$row['customer_id']] ??= [];
12+
$customers[$row['customer_id']]['orders'] ??= [];
13+
$customers[$row['customer_id']]['orders'][$row['order_id']] ??= [];
14+
15+
$customers[$row['customer_id']]['orders'][$row['order_id']]['balance_forward'] ??= 0;
16+
$customers[$row['customer_id']]['orders'][$row['order_id']]['new_invoice'] ??= 0;
17+
$customers[$row['customer_id']]['orders'][$row['order_id']]['payments'] ??= 0;
18+
$customers[$row['customer_id']]['orders'][$row['order_id']]['balance'] ??= $row['order_total'];
19+
}
20+
};

0 commit comments

Comments
 (0)