Skip to content

Commit b3ee78e

Browse files
committed
assert based on original-node
1 parent acc8721 commit b3ee78e

6 files changed

Lines changed: 10 additions & 15 deletions

File tree

src/Node/MethodCallableNode.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ public function getOriginalNode(): Expr\MethodCall|Expr\NullsafeMethodCall
3939
return $this->originalNode;
4040
}
4141

42-
/**
43-
* Whether the original expression combined the nullsafe operator with the
44-
* first-class callable syntax (`$foo?->bar(...)`), which is a fatal error in PHP.
45-
*/
46-
public function isNullsafe(): bool
47-
{
48-
return $this->originalNode instanceof Expr\NullsafeMethodCall;
49-
}
50-
5142
#[Override]
5243
public function getType(): string
5344
{

src/Rules/Methods/MethodCallableRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function processNode(Node $node, Scope $scope): array
3737
];
3838
}
3939

40-
if ($node->isNullsafe()) {
40+
if ($node->getOriginalNode() instanceof Node\Expr\NullsafeMethodCall) {
4141
return [
4242
RuleErrorBuilder::message('Cannot combine nullsafe operator with Closure creation.')
4343
->nonIgnorable()

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,9 +1605,9 @@ public function testBug9746(): void
16051605
$errors = $this->runAnalyse(__DIR__ . '/data/bug-9746.php');
16061606
$this->assertCount(2, $errors);
16071607
$this->assertSame('Call to method Bug9746\HelloWorld::sayHello() on a separate line has no effect.', $errors[0]->getMessage());
1608-
$this->assertSame(9, $errors[0]->getLine());
1608+
$this->assertSame(11, $errors[0]->getLine());
16091609
$this->assertSame('Cannot combine nullsafe operator with Closure creation.', $errors[1]->getMessage());
1610-
$this->assertSame(9, $errors[1]->getLine());
1610+
$this->assertSame(11, $errors[1]->getLine());
16111611
}
16121612

16131613
/**

tests/PHPStan/Analyser/data/bug-9746.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types = 1);
1+
<?php // lint >= 8.1
2+
3+
declare(strict_types = 1);
24

35
namespace Bug9746;
46

tests/PHPStan/Rules/Methods/MethodCallableRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testNullsafe(): void
6565
$this->analyse([__DIR__ . '/data/method-callable-nullsafe.php'], [
6666
[
6767
'Cannot combine nullsafe operator with Closure creation.',
68-
18,
68+
20,
6969
],
7070
]);
7171
}

tests/PHPStan/Rules/Methods/data/method-callable-nullsafe.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types = 1);
1+
<?php // lint >= 8.1
2+
3+
declare(strict_types = 1);
24

35
namespace MethodCallableNullsafe;
46

0 commit comments

Comments
 (0)