Skip to content

Commit 52788e6

Browse files
phpstan-botclaude
andcommitted
Address review: add rule test and post-chain type assertions for bug-6934
- Add CallMethodsRule test to verify no parameter type error on $node?->parentNode?->removeChild($node) - Assert $node remains DOMNode|null after the nullsafe chain - Assert $foo remains Foo|null after the nullsafe chain Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 824d1cd commit 52788e6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

tests/PHPStan/Analyser/nsrt/bug-6934.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
function removeFromParent(?DOMNode $node): void {
1111
$node?->parentNode?->removeChild($node);
12+
assertType('DOMNode|null', $node);
1213
}
1314

1415
function testNarrowing(?DOMNode $node): void {
@@ -23,4 +24,5 @@ public function doSomething(): string {
2324

2425
function testNullsafeChainArgs(?Foo $foo): void {
2526
$foo?->doSomething(assertType('Bug6934\Foo', $foo));
27+
assertType('Bug6934\Foo|null', $foo);
2628
}

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,6 +3945,15 @@ public function testBug7369(): void
39453945
]);
39463946
}
39473947

3948+
#[RequiresPhp('>= 8.0')]
3949+
public function testBug6934(): void
3950+
{
3951+
$this->checkThisOnly = false;
3952+
$this->checkNullables = true;
3953+
$this->checkUnionTypes = true;
3954+
$this->analyse([__DIR__ . '/data/bug-6934.php'], []);
3955+
}
3956+
39483957
public function testBug11463(): void
39493958
{
39503959
$this->checkThisOnly = false;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug6934Rule;
6+
7+
use DOMNode;
8+
9+
function removeFromParent(?DOMNode $node): void {
10+
$node?->parentNode?->removeChild($node);
11+
}

0 commit comments

Comments
 (0)