diff --git a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/BinaryOpStandaloneAssignsToDirectRectorTest.php b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/BinaryOpStandaloneAssignsToDirectRectorTest.php deleted file mode 100644 index 66dba79b1ac..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/BinaryOpStandaloneAssignsToDirectRectorTest.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/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_any_call_like_with_args.php.inc b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_any_call_like_with_args.php.inc deleted file mode 100644 index 5d481afcc1e..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_any_call_like_with_args.php.inc +++ /dev/null @@ -1,16 +0,0 @@ - $second; - } -} diff --git a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_by_ref_from_param_variable.php.inc b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_by_ref_from_param_variable.php.inc deleted file mode 100644 index 1362e570fc3..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_by_ref_from_param_variable.php.inc +++ /dev/null @@ -1,14 +0,0 @@ - $second; - } -} diff --git a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_compare_assign_op.php.inc b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_compare_assign_op.php.inc deleted file mode 100644 index 5da4308b5e0..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_compare_assign_op.php.inc +++ /dev/null @@ -1,14 +0,0 @@ - $second; - } -} diff --git a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_compare_binary_op.php.inc b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_compare_binary_op.php.inc deleted file mode 100644 index 4f9d2a3996a..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_compare_binary_op.php.inc +++ /dev/null @@ -1,14 +0,0 @@ - $second; - } -} diff --git a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_different_order.php.inc b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_different_order.php.inc deleted file mode 100644 index 063f1eff01b..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_different_order.php.inc +++ /dev/null @@ -1,14 +0,0 @@ -createLongValue(100); - $second = $this->createLongValue(200); - - return $first <=> $second; - } - - private function createLongValue($value) - { - return $value . ' is long'; - } -} diff --git a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_non_variable_assign.php.inc b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_non_variable_assign.php.inc deleted file mode 100644 index f5097685fdd..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_non_variable_assign.php.inc +++ /dev/null @@ -1,16 +0,0 @@ -number = 200; - - return $first <=> $this->number; - } -} diff --git a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/some_separated_assign.php.inc b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/some_separated_assign.php.inc deleted file mode 100644 index de72da9b732..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/some_separated_assign.php.inc +++ /dev/null @@ -1,30 +0,0 @@ - $second; - } -} - -?> ------ - 200; - } -} - -?> diff --git a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/two_bare_getters.php.inc b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/two_bare_getters.php.inc deleted file mode 100644 index 3bd4dc89b43..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/two_bare_getters.php.inc +++ /dev/null @@ -1,34 +0,0 @@ -getSome(); - $second = $secondSomeGetter->getSome(); - - return $first <=> $second; - } -} - -?> ------ -getSome() <=> $secondSomeGetter->getSome(); - } -} - -?> diff --git a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Source/SomeGetter.php b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Source/SomeGetter.php deleted file mode 100644 index 789f2bd6288..00000000000 --- a/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Source/SomeGetter.php +++ /dev/null @@ -1,11 +0,0 @@ -withRules([BinaryOpStandaloneAssignsToDirectRector::class]); diff --git a/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php b/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php index 8ab71fb74a6..eb39b4384b3 100644 --- a/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php @@ -5,27 +5,19 @@ namespace Rector\CodingStyle\Rector\ClassMethod; use PhpParser\Node; -use PhpParser\Node\Expr\Assign; -use PhpParser\Node\Expr\BinaryOp; -use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\Closure; -use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Function_; -use PhpParser\Node\Stmt\Return_; -use Rector\CodingStyle\ValueObject\VariableAndExprAssign; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; -use Rector\ValueObject\PhpVersionFeature; -use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\Tests\CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector\BinaryOpStandaloneAssignsToDirectRectorTest + * @deprecated This rule is deprecated, as it targets a very specific shape of 3 statements only and its purpose is unclear. */ -final class BinaryOpStandaloneAssignsToDirectRector extends AbstractRector implements MinPhpVersionInterface +final class BinaryOpStandaloneAssignsToDirectRector extends AbstractRector implements DeprecatedInterface { public function getRuleDefinition(): RuleDefinition { @@ -65,112 +57,9 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if ($node->stmts === null) { - return null; - } - - if (count($node->stmts) !== 3) { - return null; - } - - $firstStmt = $node->stmts[0]; - $secondStmt = $node->stmts[1]; - $thirdStmt = $node->stmts[2]; - - if (! $thirdStmt instanceof Return_) { - return null; - } - - $firstVariableAndExprAssign = $this->matchToVariableAssignExpr($firstStmt); - if (! $firstVariableAndExprAssign instanceof VariableAndExprAssign) { - return null; - } - - $secondVariableAndExprAssign = $this->matchToVariableAssignExpr($secondStmt); - if (! $secondVariableAndExprAssign instanceof VariableAndExprAssign) { - return null; - } - - if (! $thirdStmt->expr instanceof BinaryOp) { - return null; - } - - $binaryOp = $thirdStmt->expr; - - if (! $this->nodeComparator->areNodesEqual($binaryOp->left, $firstVariableAndExprAssign->getVariable())) { - return null; - } - - if (! $this->nodeComparator->areNodesEqual($binaryOp->right, $secondVariableAndExprAssign->getVariable())) { - return null; - } - - $resolveParamByRefVariables = $this->resolveParamByRefVariables($node); - if ($this->isNames($binaryOp->left, $resolveParamByRefVariables)) { - return null; - } - - if ($this->isNames($binaryOp->right, $resolveParamByRefVariables)) { - return null; - } - - $binaryOp->left = $firstVariableAndExprAssign->getExpr(); - $binaryOp->right = $secondVariableAndExprAssign->getExpr(); - - $node->stmts = [$thirdStmt]; - return $node; - } - - public function provideMinPhpVersion(): int - { - return PhpVersionFeature::VARIADIC_PARAM; - } - - /** - * @return string[] - */ - private function resolveParamByRefVariables(ClassMethod|Function_|Closure $node): array - { - $paramByRefVariables = []; - foreach ($node->params as $param) { - if (! $param->var instanceof Variable) { - continue; - } - - if (! $param->byRef) { - continue; - } - - $paramByRefVariables[] = $this->getName($param); - } - - return $paramByRefVariables; - } - - private function matchToVariableAssignExpr(Stmt $stmt): ?VariableAndExprAssign - { - if (! $stmt instanceof Expression) { - return null; - } - - if (! $stmt->expr instanceof Assign) { - return null; - } - - $assign = $stmt->expr; - if (! $assign->var instanceof Variable) { - return null; - } - - // skip complex cases - if ($assign->expr instanceof CallLike && ! $assign->expr->isFirstClassCallable() && $assign->expr->getArgs() !== []) { - return null; - } - - if ($assign->expr instanceof BinaryOp) { - return null; - } - - return new VariableAndExprAssign($assign->var, $assign->expr); + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as it covers a very specific shape of code with unclear purpose', + self::class + )); } } diff --git a/rules/CodingStyle/ValueObject/VariableAndExprAssign.php b/rules/CodingStyle/ValueObject/VariableAndExprAssign.php deleted file mode 100644 index dc5bb7295e9..00000000000 --- a/rules/CodingStyle/ValueObject/VariableAndExprAssign.php +++ /dev/null @@ -1,27 +0,0 @@ -variable; - } - - public function getExpr(): Expr - { - return $this->expr; - } -} diff --git a/src/Config/Level/CodingStyleLevel.php b/src/Config/Level/CodingStyleLevel.php index b778af5e4ec..ea8a6501cb0 100644 --- a/src/Config/Level/CodingStyleLevel.php +++ b/src/Config/Level/CodingStyleLevel.php @@ -8,7 +8,6 @@ use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector; use Rector\CodingStyle\Rector\ClassConst\SplitGroupedClassConstantsRector; use Rector\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector; -use Rector\CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector; use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector; use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector; @@ -73,7 +72,6 @@ final class CodingStyleLevel SplitGroupedPropertiesRector::class, SplitGroupedClassConstantsRector::class, RemoveUselessAliasInUseStatementRector::class, - BinaryOpStandaloneAssignsToDirectRector::class, MinMaxToClampRector::class, ];