From cd5ecca14ccce52e364a79493c91664269b7ccfe Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 6 Aug 2026 00:56:48 +0200 Subject: [PATCH] [EarlyReturn] Deprecate ReturnBinaryOrToEarlyReturnRector --- config/set/early-return.php | 2 - .../Fixture/and_in_next.php.inc | 33 ------- .../Fixture/and_nested_deep.php.inc | 39 --------- .../dont_change_already_casted.php.inc | 30 ------- .../dont_change_already_return_typed.php.inc | 50 ----------- .../Fixture/fixture.php.inc | 30 ------- .../Fixture/identical_compare.php.inc | 30 ------- .../Fixture/last_return_bool.php.inc | 53 ----------- .../Fixture/multiple_binary_or.php.inc | 36 -------- ...e_binary_or_start_with_method_call.php.inc | 37 -------- .../Fixture/not_object_call_in_last.php.inc | 30 ------- .../Fixture/skip_not_object_call.php.inc | 13 --- .../Fixture/some_not_identical.php.inc | 30 ------- .../Fixture/truthy_negation.php.inc | 30 ------- .../Fixture/with_comment.php.inc | 44 ---------- .../ReturnBinaryOrToEarlyReturnRectorTest.php | 28 ------ .../config/configured_rule.php | 9 -- .../ReturnBinaryOrToEarlyReturnRector.php | 87 ++----------------- src/NodeAnalyzer/CallAnalyzer.php | 9 -- src/PhpParser/Node/AssignAndBinaryMap.php | 28 +----- .../Fixture/some_fixture.php.inc | 6 +- .../config/configured_rule.php | 2 - 22 files changed, 12 insertions(+), 644 deletions(-) delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/and_in_next.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/and_nested_deep.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/dont_change_already_casted.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/dont_change_already_return_typed.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/fixture.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/identical_compare.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/last_return_bool.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/multiple_binary_or.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/multiple_binary_or_start_with_method_call.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/not_object_call_in_last.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/skip_not_object_call.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/some_not_identical.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/truthy_negation.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/with_comment.php.inc delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/ReturnBinaryOrToEarlyReturnRectorTest.php delete mode 100644 rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/config/configured_rule.php diff --git a/config/set/early-return.php b/config/set/early-return.php index b16ed67649c..4e41135f971 100644 --- a/config/set/early-return.php +++ b/config/set/early-return.php @@ -5,12 +5,10 @@ use Rector\Config\RectorConfig; use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector; use Rector\EarlyReturn\Rector\If_\ChangeNestedIfsToEarlyReturnRector; -use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->rules([ ChangeNestedForeachIfsToEarlyContinueRector::class, ChangeNestedIfsToEarlyReturnRector::class, - ReturnBinaryOrToEarlyReturnRector::class, ]); }; diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/and_in_next.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/and_in_next.php.inc deleted file mode 100644 index 71d884055e8..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/and_in_next.php.inc +++ /dev/null @@ -1,33 +0,0 @@ -something() || $this->somethingelse() && $this->anotherelse() || $this->last(); - } -} - -?> ------ -something()) { - return true; - } - if ($this->somethingelse() && $this->anotherelse()) { - return true; - } - return (bool) $this->last(); - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/and_nested_deep.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/and_nested_deep.php.inc deleted file mode 100644 index a55827d018e..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/and_nested_deep.php.inc +++ /dev/null @@ -1,39 +0,0 @@ -donation === null - || ($this->commission > 0 && $this->transaction === null) - || $this->somethingElse() - || $this->anotherThing(); - } -} - -?> ------ -donation === null) { - return true; - } - if ($this->commission > 0 && $this->transaction === null) { - return true; - } - if ($this->somethingElse()) { - return true; - } - return (bool) $this->anotherThing(); - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/dont_change_already_casted.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/dont_change_already_casted.php.inc deleted file mode 100644 index 6ce70a592d6..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/dont_change_already_casted.php.inc +++ /dev/null @@ -1,30 +0,0 @@ -something() || (bool) $this->somethingelse(); - } -} - -?> ------ -something()) { - return true; - } - return (bool) $this->somethingelse(); - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/dont_change_already_return_typed.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/dont_change_already_return_typed.php.inc deleted file mode 100644 index 61228f76923..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/dont_change_already_return_typed.php.inc +++ /dev/null @@ -1,50 +0,0 @@ -something() || $this->somethingElse(); - } - - private function something(): bool - { - return true; - } - - private function somethingElse(): bool - { - return true; - } -} - -?> ------ -something()) { - return true; - } - return $this->somethingElse(); - } - - private function something(): bool - { - return true; - } - - private function somethingElse(): bool - { - return true; - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/fixture.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/fixture.php.inc deleted file mode 100644 index e5660cbbc39..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,30 +0,0 @@ -something() || $this->somethingElse(); - } -} - -?> ------ -something()) { - return true; - } - return (bool) $this->somethingElse(); - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/identical_compare.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/identical_compare.php.inc deleted file mode 100644 index b802529800b..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/identical_compare.php.inc +++ /dev/null @@ -1,30 +0,0 @@ -something() === 1 || !$this->somethingElse(); - } -} - -?> ------ -something() === 1) { - return true; - } - return !$this->somethingElse(); - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/last_return_bool.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/last_return_bool.php.inc deleted file mode 100644 index d085effec06..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/last_return_bool.php.inc +++ /dev/null @@ -1,53 +0,0 @@ -something() || $this->getSomethingElse(); - } - - public function accept2() - { - return $this->something() || $this->somethingelse() === 'something else'; - } - - private function getSomethingElse(): bool - { - return true; - } -} - -?> ------ -something()) { - return true; - } - return $this->getSomethingElse(); - } - - public function accept2() - { - if ($this->something()) { - return true; - } - return $this->somethingelse() === 'something else'; - } - - private function getSomethingElse(): bool - { - return true; - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/multiple_binary_or.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/multiple_binary_or.php.inc deleted file mode 100644 index 652d19293bc..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/multiple_binary_or.php.inc +++ /dev/null @@ -1,36 +0,0 @@ -something() || $this->somethingelse() || $this->anotherelse() || $this->last(); - } -} - -?> ------ -something()) { - return true; - } - if ($this->somethingelse()) { - return true; - } - if ($this->anotherelse()) { - return true; - } - return (bool) $this->last(); - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/multiple_binary_or_start_with_method_call.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/multiple_binary_or_start_with_method_call.php.inc deleted file mode 100644 index 312432d6612..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/multiple_binary_or_start_with_method_call.php.inc +++ /dev/null @@ -1,37 +0,0 @@ -execute() || $a || $b; - } - - private function execute() {} -} - -?> ------ -execute()) { - return true; - } - if ($a) { - return true; - } - return (bool) $b; - } - - private function execute() {} -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/not_object_call_in_last.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/not_object_call_in_last.php.inc deleted file mode 100644 index e29cc66265c..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/not_object_call_in_last.php.inc +++ /dev/null @@ -1,30 +0,0 @@ -something() || true; - } -} - -?> ------ -something()) { - return true; - } - return true; - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/skip_not_object_call.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/skip_not_object_call.php.inc deleted file mode 100644 index 4f6a16dfbc4..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/skip_not_object_call.php.inc +++ /dev/null @@ -1,13 +0,0 @@ -something || $this->somethingelse; - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/some_not_identical.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/some_not_identical.php.inc deleted file mode 100644 index 691db852ac6..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/some_not_identical.php.inc +++ /dev/null @@ -1,30 +0,0 @@ -something() !== 1 || !$this->somethingelse(); - } -} - -?> ------ -something() !== 1) { - return true; - } - return !$this->somethingelse(); - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/truthy_negation.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/truthy_negation.php.inc deleted file mode 100644 index 203d696a15f..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/truthy_negation.php.inc +++ /dev/null @@ -1,30 +0,0 @@ -something() || !$this->somethingelse(); - } -} - -?> ------ -something()) { - return true; - } - return !$this->somethingelse(); - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/with_comment.php.inc b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/with_comment.php.inc deleted file mode 100644 index 527f8032a06..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/Fixture/with_comment.php.inc +++ /dev/null @@ -1,44 +0,0 @@ -something() || $this->somethingElse(); - } - - // another next comment - return 1; - } -} - -?> ------ -something()) { - return true; - } - return (bool) $this->somethingElse(); - } - - // another next comment - return 1; - } -} - -?> diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/ReturnBinaryOrToEarlyReturnRectorTest.php b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/ReturnBinaryOrToEarlyReturnRectorTest.php deleted file mode 100644 index a0255c0f729..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/ReturnBinaryOrToEarlyReturnRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/config/configured_rule.php b/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/config/configured_rule.php deleted file mode 100644 index 535296e20e0..00000000000 --- a/rules-tests/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([ReturnBinaryOrToEarlyReturnRector::class]); diff --git a/rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php b/rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php index 0d761d8925b..34942cc8380 100644 --- a/rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php +++ b/rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php @@ -5,28 +5,18 @@ namespace Rector\EarlyReturn\Rector\Return_; use PhpParser\Node; -use PhpParser\Node\Expr; -use PhpParser\Node\Expr\BinaryOp\BooleanOr; -use PhpParser\Node\Stmt\If_; -use PhpParser\Node\Stmt\Return_; -use Rector\NodeAnalyzer\CallAnalyzer; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; +use Rector\Exception\ShouldNotHappenException; use Rector\PhpParser\Enum\NodeGroup; -use Rector\PhpParser\Node\AssignAndBinaryMap; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\Tests\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector\ReturnBinaryOrToEarlyReturnRectorTest + * @deprecated This rule is deprecated, as splitting a single return into multiple early returns makes the code longer and harder to read. */ -final class ReturnBinaryOrToEarlyReturnRector extends AbstractRector +final class ReturnBinaryOrToEarlyReturnRector extends AbstractRector implements DeprecatedInterface { - public function __construct( - private readonly AssignAndBinaryMap $assignAndBinaryMap, - private readonly CallAnalyzer $callAnalyzer - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change single return of `||` to early returns', [ @@ -66,72 +56,11 @@ public function getNodeTypes(): array return NodeGroup::STMTS_AWARE; } - /** - * @param StmtsAware $node - */ public function refactor(Node $node): ?Node { - if ($node->stmts === null) { - return null; - } - - $hasChanged = false; - - foreach ($node->stmts as $key => $stmt) { - if (! $stmt instanceof Return_) { - continue; - } - - if (! $stmt->expr instanceof BooleanOr) { - continue; - } - - $booleanOr = $stmt->expr; - - // the right side becomes the final return, the left operands become early returns - $left = $booleanOr->left; - $leftOperands = $left instanceof BooleanOr ? $this->flattenBooleanOr($left) : [$left]; - - $ifs = []; - foreach ($leftOperands as $leftOperand) { - $ifs[] = new If_($leftOperand, [ - 'stmts' => [new Return_($this->nodeFactory->createTrue())], - ]); - } - - if (! $this->callAnalyzer->doesIfHasObjectCall($ifs)) { - continue; - } - - $this->mirrorComments($ifs[0], $stmt); - - $lastReturnExpr = $this->assignAndBinaryMap->getTruthyExpr($booleanOr->right); - - $ifsWithLastIf = array_merge($ifs, [new Return_($lastReturnExpr)]); - - array_splice($node->stmts, $key, 1, $ifsWithLastIf); - $hasChanged = true; - } - - if ($hasChanged) { - return $node; - } - - return null; - } - - /** - * Flatten a left-associative "||" chain into its operands, in source order. - * - * @return Expr[] - */ - private function flattenBooleanOr(BooleanOr $booleanOr): array - { - $left = $booleanOr->left; - - $operands = $left instanceof BooleanOr ? $this->flattenBooleanOr($left) : [$left]; - $operands[] = $booleanOr->right; - - return $operands; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as splitting a single return into multiple early returns makes the code longer and harder to read', + self::class + )); } } diff --git a/src/NodeAnalyzer/CallAnalyzer.php b/src/NodeAnalyzer/CallAnalyzer.php index 4c89e952fab..4e3846055f2 100644 --- a/src/NodeAnalyzer/CallAnalyzer.php +++ b/src/NodeAnalyzer/CallAnalyzer.php @@ -11,7 +11,6 @@ use PhpParser\Node\Expr\NullsafeMethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Stmt\If_; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\ObjectType; @@ -48,14 +47,6 @@ public function isObjectCall(Expr $expr): bool ); } - /** - * @param If_[] $ifs - */ - public function doesIfHasObjectCall(array $ifs): bool - { - return array_any($ifs, fn (If_ $if): bool => $this->isObjectCall($if->cond)); - } - public function isNewInstance(Variable $variable): bool { $scope = $variable->getAttribute(AttributeKey::SCOPE); diff --git a/src/PhpParser/Node/AssignAndBinaryMap.php b/src/PhpParser/Node/AssignAndBinaryMap.php index 69e98bd89d5..af424f5aea1 100644 --- a/src/PhpParser/Node/AssignAndBinaryMap.php +++ b/src/PhpParser/Node/AssignAndBinaryMap.php @@ -5,7 +5,6 @@ namespace Rector\PhpParser\Node; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\AssignOp; use PhpParser\Node\Expr\AssignOp\BitwiseAnd as AssignBitwiseAnd; use PhpParser\Node\Expr\AssignOp\BitwiseOr as AssignBitwiseOr; @@ -40,9 +39,6 @@ use PhpParser\Node\Expr\BinaryOp\ShiftRight; use PhpParser\Node\Expr\BinaryOp\Smaller; use PhpParser\Node\Expr\BinaryOp\SmallerOrEqual; -use PhpParser\Node\Expr\BooleanNot; -use PhpParser\Node\Expr\Cast\Bool_; -use Rector\NodeTypeResolver\NodeTypeResolver; final class AssignAndBinaryMap { @@ -83,9 +79,8 @@ final class AssignAndBinaryMap */ private array $binaryOpToAssignClasses; - public function __construct( - private readonly NodeTypeResolver $nodeTypeResolver - ) { + public function __construct() + { /** @var array, class-string> $binaryClassesToAssignOp */ $binaryClassesToAssignOp = array_flip(self::ASSIGN_OP_TO_BINARY_OP_CLASSES); $this->binaryOpToAssignClasses = $binaryClassesToAssignOp; @@ -117,23 +112,4 @@ public function getInversed(BinaryOp $binaryOp): ?string $nodeClass = $binaryOp::class; return self::BINARY_OP_TO_INVERSE_CLASSES[$nodeClass] ?? null; } - - public function getTruthyExpr(Expr $expr): Expr - { - if ($expr instanceof Bool_) { - return $expr; - } - - if ($expr instanceof BooleanNot) { - return $expr; - } - - $exprType = $this->nodeTypeResolver->getType($expr); - // $type = $scope->getType($expr); - if ($exprType->isBoolean()->yes()) { - return $expr; - } - - return new Bool_($expr); - } } diff --git a/tests/Issues/ReplaceStmtToExpr/Fixture/some_fixture.php.inc b/tests/Issues/ReplaceStmtToExpr/Fixture/some_fixture.php.inc index f35cdd7e106..fe57f9f907d 100644 --- a/tests/Issues/ReplaceStmtToExpr/Fixture/some_fixture.php.inc +++ b/tests/Issues/ReplaceStmtToExpr/Fixture/some_fixture.php.inc @@ -52,10 +52,8 @@ final class SomeFixture if (!$user instanceof \Rector\Tests\Issues\ReplaceStmtToExpr\Source\SomeUser) { return false; } - if ($user->isFoo()) { - return true; - } - return (bool) $user->isBar(); + + return $user->isFoo() || $user->isBar(); } } diff --git a/tests/Issues/ReplaceStmtToExpr/config/configured_rule.php b/tests/Issues/ReplaceStmtToExpr/config/configured_rule.php index d7bb687f586..046c4ab4f60 100644 --- a/tests/Issues/ReplaceStmtToExpr/config/configured_rule.php +++ b/tests/Issues/ReplaceStmtToExpr/config/configured_rule.php @@ -5,13 +5,11 @@ use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector; use Rector\CodeQuality\Rector\If_\ObjectExplicitBoolCompareRector; use Rector\Config\RectorConfig; -use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector; return RectorConfig::configure() ->withRules( [ ObjectExplicitBoolCompareRector::class, FlipTypeControlToUseExclusiveTypeRector::class, - ReturnBinaryOrToEarlyReturnRector::class, ] );