From 573537024df9b0b990fc87bc6b74cb724460805b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 4 Apr 2026 10:16:48 +0700 Subject: [PATCH 1/2] [CodeQuality] Handle with assign on SimplifyIfElseToTernaryRector --- .../Fixture/with_assign.php.inc | 31 +++++++++++++++++++ .../If_/SimplifyIfElseToTernaryRector.php | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/with_assign.php.inc diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/with_assign.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/with_assign.php.inc new file mode 100644 index 00000000000..91e2cbf49c2 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/with_assign.php.inc @@ -0,0 +1,31 @@ +methodX()) { + $this->out = $a; + } else { + $this->out = $this->methodY(); + } + } +} + +?> +----- +out = ($a = $this->methodX()) ? $a : $this->methodY(); + } +} + +?> diff --git a/rules/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector.php b/rules/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector.php index 34713e3e9e6..808ac5d7136 100644 --- a/rules/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector.php +++ b/rules/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector.php @@ -125,7 +125,7 @@ public function refactor(Node $node): ?Node return null; } - if ($ternary->cond instanceof BinaryOp) { + if ($ternary->cond instanceof BinaryOp || $ternary->cond instanceof Assign) { $ternary->cond->setAttribute(AttributeKey::ORIGINAL_NODE, null); } From 936766b9dcc9f7b6fcad3748fbba683f90a0d03c Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 4 Apr 2026 03:19:26 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- rules/Php86/Rector/FuncCall/MinMaxToClampRector.php | 3 ++- src/Rector/AbstractRector.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rules/Php86/Rector/FuncCall/MinMaxToClampRector.php b/rules/Php86/Rector/FuncCall/MinMaxToClampRector.php index 5a9f2462132..6cbdf7bfd5d 100644 --- a/rules/Php86/Rector/FuncCall/MinMaxToClampRector.php +++ b/rules/Php86/Rector/FuncCall/MinMaxToClampRector.php @@ -4,6 +4,7 @@ namespace Rector\Php86\Rector\FuncCall; +use PhpParser\Node\Identifier; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; @@ -129,7 +130,7 @@ private function createClampFuncCall( private function isSupportedArg(Arg $arg): bool { - return ! $arg->unpack && $arg->name === null; + return ! $arg->unpack && !$arg->name instanceof Identifier; } /** diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index 2a5a4129a2a..57ec3ea5774 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -224,9 +224,9 @@ protected function getType(Node $node): Type /** * Use this method for getting native expr type */ - protected function getNativeType(Expr $node): Type + protected function getNativeType(Expr $expr): Type { - return $this->nodeTypeResolver->getNativeType($node); + return $this->nodeTypeResolver->getNativeType($expr); } /**