Skip to content

Commit

Permalink
Updated Rector to commit a24035cbbd7d86e6a45a025d60ebede4e00333f8
Browse files Browse the repository at this point in the history
rectorphp/rector-src@a24035c [Arguments] Remove unnecessary re-create default value param from ConstFetch on ArgumentAdderRector, set origNode = null instead (#5113)
  • Loading branch information
TomasVotruba committed Oct 4, 2023
1 parent 489d95e commit b9cc02d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;
Expand All @@ -24,8 +23,8 @@
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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -202,10 +195,19 @@ private function fillGapBetweenWithDefaultValue($node, int $position) : void
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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit b9cc02d

Please sign in to comment.