diff --git a/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php b/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php index 223aa7cc478..e176ab5840b 100644 --- a/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php +++ b/rules/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector.php @@ -8,15 +8,10 @@ use PhpParser\Node; use PhpParser\Node\ComplexType; use PhpParser\Node\Expr; -use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Param; -use PhpParser\Node\Scalar\DNumber; -use PhpParser\Node\Scalar\LNumber; -use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Reflection\MethodReflection; use Rector\Core\PhpParser\AstResolver; @@ -246,29 +241,17 @@ function (Node $subNode) use ($parentClassMethodParam): bool { private function resolveParamDefault(Expr $expr): Expr { - // re-create to avoid TokenStream error - if ($expr instanceof String_) { - return new String_($expr->value, [ - AttributeKey::KIND => $expr->getAttribute(AttributeKey::KIND), - ]); - } - - if ($expr instanceof LNumber) { - return new LNumber($expr->value); - } - - if ($expr instanceof DNumber) { - return new DNumber($expr->value); - } - - if ($expr instanceof Array_ && $expr->items === []) { - return new Array_($expr->items, [ - AttributeKey::KIND => $expr->getAttribute(AttributeKey::KIND), - ]); - } + // reset original node, to allow the printer to re-use the expr + $expr->setAttribute(AttributeKey::ORIGINAL_NODE, null); + $this->traverseNodesWithCallable( + $expr, + static function (Node $node): Node { + $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); + return $node; + } + ); - $printParamDefault = $this->betterStandardPrinter->print($expr); - return new ConstFetch(new Name($printParamDefault)); + return $expr; } private function resolveParamType(Param $param): null|Identifier|Name|ComplexType