Skip to content

Commit

Permalink
ConstantConditionRuleHelper - do not report empty(), it has a separat…
Browse files Browse the repository at this point in the history
…e rule
  • Loading branch information
ondrejmirtes committed Jan 31, 2022
1 parent 3b17acc commit fe26263
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Rules/Comparison/ConstantConditionRuleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function shouldReportAlwaysTrueByDefault(Expr $expr): bool
|| $expr instanceof Expr\BinaryOp\BooleanOr
|| $expr instanceof Expr\BinaryOp\BooleanAnd
|| $expr instanceof Expr\Ternary
|| $expr instanceof Expr\Isset_;
|| $expr instanceof Expr\Isset_
|| $expr instanceof Expr\Empty_;
}

public function shouldSkip(Scope $scope, Expr $expr): bool
Expand All @@ -38,6 +39,7 @@ public function shouldSkip(Scope $scope, Expr $expr): bool
|| $expr instanceof Expr\BinaryOp\BooleanAnd
|| $expr instanceof Expr\Ternary
|| $expr instanceof Expr\Isset_
|| $expr instanceof Expr\Empty_
|| $expr instanceof Expr\BinaryOp\Greater
|| $expr instanceof Expr\BinaryOp\GreaterOrEqual
|| $expr instanceof Expr\BinaryOp\Smaller
Expand Down
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/if-condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,20 @@ public function nestedIfConditions($mixed): void
}
}
}

class EmptyCondition
{

public function doFoo()
{
$a = 1;
if (empty($a)) {

}

if (empty($b)) {

}
}

}

0 comments on commit fe26263

Please sign in to comment.