Skip to content

Commit

Permalink
BetterNoopRule - detect FuncCall with Expr
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 18, 2024
1 parent 57b0ae0 commit b9d990b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rules/DeadCode/BetterNoopRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function processNode(Node $node, Scope $scope): array
}

if (
$expr instanceof Node\Expr\FuncCall
($expr instanceof Node\Expr\FuncCall && $expr->name instanceof Node\Name)
|| $expr instanceof Node\Expr\NullsafeMethodCall
|| $expr instanceof Node\Expr\MethodCall
|| $expr instanceof Node\Expr\New_
Expand Down
4 changes: 4 additions & 0 deletions tests/PHPStan/Rules/DeadCode/BetterNoopRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public function testRuleImpurePoints(): void
'Unused result of "&&" operator.',
10,
],
[
'Expression "$b()" on a separate line does not do anything.',
57,
],
]);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/noop-impure-points.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@ public function doAssign(bool $b): void
$b ? $this->foo = 1 : '';
}

public function doClosures(): void
{
$a = static function () {
echo '1';
};
$a();

$b = static function () {
return 1 + 1;
};
$b();
}

}

0 comments on commit b9d990b

Please sign in to comment.