From b9cc02d39e195b0b6ea6e02c75d126e0954079f4 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 4 Oct 2023 11:23:15 +0000 Subject: [PATCH] Updated Rector to commit a24035cbbd7d86e6a45a025d60ebede4e00333f8 https://github.com/rectorphp/rector-src/commit/a24035cbbd7d86e6a45a025d60ebede4e00333f8 [Arguments] Remove unnecessary re-create default value param from ConstFetch on ArgumentAdderRector, set origNode = null instead (#5113) --- .../ClassMethod/ArgumentAdderRector.php | 24 ++++++++++--------- src/Application/VersionResolver.php | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php index 96430c488bc..509e3c5df2c 100644 --- a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php +++ b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php @@ -7,7 +7,6 @@ use PhpParser\BuilderHelpers; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; -use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; @@ -24,8 +23,8 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface; use Rector\Core\Enum\ObjectReference; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\PhpParser\AstResolver; -use Rector\Core\PhpParser\Printer\BetterStandardPrinter; use Rector\Core\Rector\AbstractRector; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; @@ -51,11 +50,6 @@ final class ArgumentAdderRector extends AbstractRector implements ConfigurableRe * @var \Rector\Core\PhpParser\AstResolver */ private $astResolver; - /** - * @readonly - * @var \Rector\Core\PhpParser\Printer\BetterStandardPrinter - */ - private $betterStandardPrinter; /** * @readonly * @var \Rector\StaticTypeMapper\StaticTypeMapper @@ -69,12 +63,11 @@ final class ArgumentAdderRector extends AbstractRector implements ConfigurableRe * @var bool */ private $hasChanged = \false; - public function __construct(ArgumentAddingScope $argumentAddingScope, ChangedArgumentsDetector $changedArgumentsDetector, AstResolver $astResolver, BetterStandardPrinter $betterStandardPrinter, StaticTypeMapper $staticTypeMapper) + public function __construct(ArgumentAddingScope $argumentAddingScope, ChangedArgumentsDetector $changedArgumentsDetector, AstResolver $astResolver, StaticTypeMapper $staticTypeMapper) { $this->argumentAddingScope = $argumentAddingScope; $this->changedArgumentsDetector = $changedArgumentsDetector; $this->astResolver = $astResolver; - $this->betterStandardPrinter = $betterStandardPrinter; $this->staticTypeMapper = $staticTypeMapper; } public function getRuleDefinition() : RuleDefinition @@ -202,10 +195,19 @@ CODE_SAMPLE if (!$param->default instanceof Expr) { throw new ShouldNotHappenException('Previous position does not have default value'); } - $default = $this->betterStandardPrinter->print($param->default); - $node->args[$index] = new Arg(new ConstFetch(new Name($default))); + $node->args[$index] = new Arg($this->resolveParamDefault($param->default)); } } + private function resolveParamDefault(Expr $expr) : Expr + { + // 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; + }); + return $expr; + } /** * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node */ diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 2211e754624..bcb97d3449f 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'b491f42c2acd125671c7908a3dacd86316048809'; + public const PACKAGE_VERSION = 'a24035cbbd7d86e6a45a025d60ebede4e00333f8'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-10-04 18:13:54'; + public const RELEASE_DATE = '2023-10-04 18:20:32'; /** * @var int */