diff --git a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php index 2413470ee72..53b4dfdf20e 100644 --- a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php +++ b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php @@ -6,6 +6,7 @@ namespace Rector\DeadCode\Rector\If_; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Assign; +use PhpParser\Node\Expr\BinaryOp\BooleanAnd; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Expr\Variable; @@ -84,10 +85,13 @@ CODE_SAMPLE } /** * @param If_ $node - * @return int|null|Stmt[] + * @return int|null|Stmt[]|If_ */ public function refactor(Node $node) { + if ($node->cond instanceof BooleanAnd) { + return $this->refactorIfWithBooleanAnd($node); + } if ($node->else instanceof Else_) { return null; } @@ -149,4 +153,20 @@ CODE_SAMPLE } return \false; } + private function refactorIfWithBooleanAnd(If_ $if) : ?If_ + { + if (!$if->cond instanceof BooleanAnd) { + return null; + } + $booleanAnd = $if->cond; + $leftType = $this->getType($booleanAnd->left); + if (!$leftType instanceof ConstantBooleanType) { + return null; + } + if (!$leftType->getValue()) { + return null; + } + $if->cond = $booleanAnd->right; + return $if; + } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index fad6ecc9ce4..bf7025025d0 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'da67bb97a141fd0feb2ab90f5576138489f2f67d'; + public const PACKAGE_VERSION = '98a2a6fd6c6d1e2db5c0143e3e66e8421904b428'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-03-21 11:03:36'; + public const RELEASE_DATE = '2024-03-21 12:21:09'; /** * @var int */