Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Rules/Methods/CallToMethodStatementWithNoDiscardRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public function processNode(Node $node, Scope $scope): array
) {
return [];
}
if (!$methodCall->name instanceof Node\Identifier) {
return [];
}

if ($methodCall->isFirstClassCallable()) {
return [];
Expand All @@ -68,11 +71,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

if (!$methodCall->name instanceof Node\Identifier) {
return [];
}
$methodName = $methodCall->name->toString();

$typeResult = $this->ruleLevelHelper->findTypeToCheck(
$scope,
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $methodCall->var),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ public function processNode(Node $node, Scope $scope): array
if ($methodCall instanceof Node\Expr\BinaryOp\Pipe) {
$methodCall = $methodCall->right;
}

if ($methodCall instanceof Node\Expr\NullsafeMethodCall) {
if (!$methodCall->name instanceof Node\Identifier) {
return [];
}
$scope = $scope->filterByTruthyValue(new Node\Expr\BinaryOp\NotIdentical($methodCall->var, new Node\Expr\ConstFetch(new Node\Name('null'))));
Copy link
Contributor Author

@staabm staabm Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevents scope filtering if possible

} elseif (!$methodCall instanceof Node\Expr\MethodCall) {
} elseif ($methodCall instanceof Node\Expr\MethodCall) {
if (!$methodCall->name instanceof Node\Identifier) {
return [];
}
} else {
return [];
}

if (!$methodCall->name instanceof Node\Identifier) {
return [];
}
$methodName = $methodCall->name->toString();

$typeResult = $this->ruleLevelHelper->findTypeToCheck(
$scope,
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $methodCall->var),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,15 @@ public function processNode(Node $node, Scope $scope): array
if (!$methodCall instanceof Node\Expr\StaticCall) {
return [];
}

if ($methodCall->isFirstClassCallable()) {
if (!$methodCall->name instanceof Node\Identifier) {
return [];
}

if (!$this->phpVersion->supportsNoDiscardAttribute()) {
if ($methodCall->isFirstClassCallable()) {
return [];
}

if (!$methodCall->name instanceof Node\Identifier) {
if (!$this->phpVersion->supportsNoDiscardAttribute()) {
return [];
}

Expand Down
Loading