diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector/Fixture/not_identical_return_false_then_true.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector/Fixture/not_identical_return_false_then_true.php.inc new file mode 100644 index 00000000000..5f8b0aa407a --- /dev/null +++ b/rules-tests/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector/Fixture/not_identical_return_false_then_true.php.inc @@ -0,0 +1,37 @@ +getContent(), "\n") !== false) { + return false; + } + + return true; + } +} + +?> +----- +getContent(), "\n") === false; + } +} + +?> diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector/Fixture/skip_not_identical_return_false_then_return_in_array.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector/Fixture/skip_not_identical_return_false_then_return_in_array.php.inc new file mode 100644 index 00000000000..d2d4758b8f0 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector/Fixture/skip_not_identical_return_false_then_return_in_array.php.inc @@ -0,0 +1,17 @@ +valueResolver->isTrue($innerIfInnerNode)) { $newReturnNode = $this->processReturnTrue($node, $nextNode); } elseif ($this->valueResolver->isFalse($innerIfInnerNode)) { - $newReturnNode = $this->processReturnFalse($node, $nextNode); + /** @var Expr $expr */ + $expr = $nextNode->expr; + if ($node->cond instanceof NotIdentical && $this->valueResolver->isTrue($expr)) { + $node->cond = new Identical($node->cond->left, $node->cond->right); + $newReturnNode = $this->processReturnTrue($node, $nextNode); + } else { + $newReturnNode = $this->processReturnFalse($node, $nextNode); + } } else { return null; } @@ -122,7 +129,7 @@ private function shouldSkip(If_ $if): bool return true; } - if ($nextNode->expr === null) { + if (! $nextNode->expr instanceof Expr) { return true; } @@ -136,7 +143,7 @@ private function shouldSkip(If_ $if): bool return ! $this->valueResolver->isTrueOrFalse($nextNode->expr); } - return true; + return ! $if->cond instanceof NotIdentical; } private function processReturnTrue(If_ $if, Return_ $nextReturnNode): Return_ diff --git a/rules/DowngradePhp74/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector.php b/rules/DowngradePhp74/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector.php index ecaa6672adf..9d9bec2b756 100644 --- a/rules/DowngradePhp74/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector.php +++ b/rules/DowngradePhp74/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector.php @@ -78,10 +78,6 @@ private function shouldRefactor(FuncCall $funcCall): bool } // If param is provided, do nothing - if ($funcCall->args !== []) { - return false; - } - - return true; + return $funcCall->args === []; } } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php index 88c295929f6..a73e9f3b943 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php @@ -133,11 +133,7 @@ private function shouldSkip(ClassMethod $classMethod): bool return false; } - if ($classLike->extends !== null) { - return false; - } - - return true; + return $classLike->extends === null; } // skip interface without parents diff --git a/src/PhpParser/Comparing/ConditionSearcher.php b/src/PhpParser/Comparing/ConditionSearcher.php index c37b487892f..eb5488dcca3 100644 --- a/src/PhpParser/Comparing/ConditionSearcher.php +++ b/src/PhpParser/Comparing/ConditionSearcher.php @@ -101,10 +101,6 @@ private function hasVariableDeclaration(Variable $variable, Stmt $stmt): bool return false; } - if ($variable->name !== $assignVar->name) { - return false; - } - - return true; + return $variable->name === $assignVar->name; } }