Skip to content

Commit b599127

Browse files
phpstan-botclaude
andcommitted
Add test case for promoted hooked properties in null coalesce check
Add a separate PHP 8.4 test method covering promoted hooked properties that are always initialized and cannot be unset. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9846969 commit b599127

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,17 @@ public function testBug14459(): void
403403
]);
404404
}
405405

406+
#[RequiresPhp('>= 8.4')]
407+
public function testBug14459Hooked(): void
408+
{
409+
$this->analyse([__DIR__ . '/data/bug-14459-hooked.php'], [
410+
[
411+
'Property Bug14459Hooked\DtoHooked::$policyholderId (stdClass) on left side of ?? is not nullable.',
412+
21,
413+
],
414+
]);
415+
}
416+
406417
public function testBug14393(): void
407418
{
408419
$this->analyse([__DIR__ . '/data/bug-14393.php'], [
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php // lint >= 8.4
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug14459Hooked;
6+
7+
final class DtoHooked
8+
{
9+
public function __construct(
10+
public \stdClass $policyholderId {
11+
set => $value;
12+
},
13+
public ?\stdClass $nullablePolicyholderId {
14+
set => $value;
15+
},
16+
) {}
17+
}
18+
19+
function testHooked(DtoHooked $dto): \stdClass
20+
{
21+
$x = $dto->policyholderId ?? new \stdClass();
22+
return $x;
23+
}
24+
25+
function testHookedNullable(DtoHooked $dto): \stdClass
26+
{
27+
$x = $dto->nullablePolicyholderId ?? new \stdClass();
28+
return $x;
29+
}

0 commit comments

Comments
 (0)