diff --git a/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/mixed.php.inc b/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/mixed.php.inc new file mode 100644 index 00000000000..f7b237e74ab --- /dev/null +++ b/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/mixed.php.inc @@ -0,0 +1,53 @@ + +----- + diff --git a/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/multi_and.php.inc b/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/multi_and.php.inc new file mode 100644 index 00000000000..e6d91ab02ea --- /dev/null +++ b/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/multi_and.php.inc @@ -0,0 +1,32 @@ + +----- + diff --git a/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/multi_or.php.inc b/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/multi_or.php.inc new file mode 100644 index 00000000000..7ef5dc4470f --- /dev/null +++ b/rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture/multi_or.php.inc @@ -0,0 +1,32 @@ + +----- + diff --git a/rules/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector.php b/rules/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector.php index f3aff4d44cc..69aef9327b9 100644 --- a/rules/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector.php +++ b/rules/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector.php @@ -55,6 +55,23 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + return $this->refactorLogicalToBoolean($node); + } + + private function refactorLogicalToBoolean(LogicalOr|LogicalAnd $node): BooleanAnd|BooleanOr + { + if ($node->left instanceof LogicalOr || $node->left instanceof LogicalAnd) { + $node->left = $this->refactorLogicalToBoolean( + $node->left, + ); + } + + if ($node->right instanceof LogicalOr || $node->right instanceof LogicalAnd) { + $node->right = $this->refactorLogicalToBoolean( + $node->right, + ); + } + if ($node instanceof LogicalOr) { return new BooleanOr($node->left, $node->right); }