diff --git a/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php b/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php index d3aaa7050a7..a82a3fabb13 100644 --- a/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php +++ b/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php @@ -65,7 +65,7 @@ public function findUnusedAssignment( $traverser->addVisitor($visitor); $traverser->traverse([$rhs_exp]); - $rhs_exp_trivial = (count($visitor->getNonTrivialExpr()) === 0); + $rhs_exp_trivial = !$visitor->hasNonTrivialExpr(); if ($rhs_exp_trivial) { $treat_as_expr = false; diff --git a/src/Psalm/Internal/PhpVisitor/CheckTrivialExprVisitor.php b/src/Psalm/Internal/PhpVisitor/CheckTrivialExprVisitor.php index 4fe4afe5269..4179ac0d0e6 100644 --- a/src/Psalm/Internal/PhpVisitor/CheckTrivialExprVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/CheckTrivialExprVisitor.php @@ -9,10 +9,7 @@ */ final class CheckTrivialExprVisitor extends PhpParser\NodeVisitorAbstract { - /** - * @var array - */ - protected array $non_trivial_expr = []; + private bool $has_non_trivial_expr = false; private function checkNonTrivialExpr(PhpParser\Node\Expr $node): bool { @@ -55,7 +52,7 @@ public function enterNode(PhpParser\Node $node): ?int if ($node instanceof PhpParser\Node\Expr) { // Check for Non-Trivial Expression first if ($this->checkNonTrivialExpr($node)) { - $this->non_trivial_expr[] = $node; + $this->has_non_trivial_expr = true; return PhpParser\NodeTraverser::STOP_TRAVERSAL; } @@ -70,11 +67,8 @@ public function enterNode(PhpParser\Node $node): ?int return null; } - /** - * @return array - */ - public function getNonTrivialExpr(): array + public function hasNonTrivialExpr(): bool { - return $this->non_trivial_expr; + return $this->has_non_trivial_expr; } }