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); } 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); } /**