From 2ca187cd94e24738caf4913219ddcb2b989a7db0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 17:36:51 +0700 Subject: [PATCH 1/3] [CodingStyle] Skip by ref params on BinaryOpStandaloneAssignsToDirectRector --- .../skip_by_ref_from_param_variable.php.inc | 14 ++++++++++++++ .../BinaryOpStandaloneAssignsToDirectRector.php | 1 + 2 files changed, 15 insertions(+) create mode 100644 rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_by_ref_from_param_variable.php.inc 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 new file mode 100644 index 00000000000..1362e570fc3 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector/Fixture/skip_by_ref_from_param_variable.php.inc @@ -0,0 +1,14 @@ + $second; + } +} diff --git a/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php b/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php index e4c9eaf1378..c03aad39dee 100644 --- a/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Param; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; From 68892af8e8f71890aa8522cbf0dabda2410c2833 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 11 Oct 2025 10:40:22 +0000 Subject: [PATCH 2/3] [ci-review] Rector Rectify --- .../ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php | 1 - 1 file changed, 1 deletion(-) diff --git a/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php b/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php index c03aad39dee..e4c9eaf1378 100644 --- a/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php @@ -10,7 +10,6 @@ use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Param; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; From 1648b6a3d90acee9a038c7fef6466941980b4f3e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 17:41:05 +0700 Subject: [PATCH 3/3] fix --- ...inaryOpStandaloneAssignsToDirectRector.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php b/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php index e4c9eaf1378..cb8e16ee622 100644 --- a/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php @@ -105,6 +105,15 @@ public function refactor(Node $node): ?Node 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(); @@ -117,6 +126,32 @@ 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; + } + + $paramName = $this->getName($param->var); + if ($paramName === null) { + continue; + } + + $paramByRefVariables[] = $paramName; + } + + return $paramByRefVariables; + } + private function matchToVariableAssignExpr(Stmt $stmt): ?VariableAndExprAssign { if (! $stmt instanceof Expression) {