Skip to content

Commit

Permalink
Merge pull request #10612 from edsrzf/rework-trivial-expr
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan authored Jan 29, 2024
2 parents 45f3218 + 98d98be commit 79b67f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions src/Psalm/Internal/PhpVisitor/CheckTrivialExprVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
*/
final class CheckTrivialExprVisitor extends PhpParser\NodeVisitorAbstract
{
/**
* @var array<int, PhpParser\Node\Expr>
*/
protected array $non_trivial_expr = [];
private bool $has_non_trivial_expr = false;

private function checkNonTrivialExpr(PhpParser\Node\Expr $node): bool
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -70,11 +67,8 @@ public function enterNode(PhpParser\Node $node): ?int
return null;
}

/**
* @return array<int, PhpParser\Node\Expr>
*/
public function getNonTrivialExpr(): array
public function hasNonTrivialExpr(): bool
{
return $this->non_trivial_expr;
return $this->has_non_trivial_expr;
}
}

0 comments on commit 79b67f8

Please sign in to comment.