mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit fe2c85cde9f06c2ccb0e6e7bbbb24f8def25efa9
fe2c85cde9
[NodeFactory] Add new method: createReprintedExpr() to create re-printed Expr that can be used to pull default Expr from Param to be re-used (#5114)
This commit is contained in:
parent
b9cc02d39e
commit
68e74833fe
@ -24,7 +24,6 @@ use Rector\Core\Enum\ObjectReference;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\PhpParser\AstResolver;
|
||||
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;
|
||||
@ -195,19 +194,9 @@ CODE_SAMPLE
|
||||
if (!$param->default instanceof Expr) {
|
||||
throw new ShouldNotHappenException('Previous position does not have default value');
|
||||
}
|
||||
$node->args[$index] = new Arg($this->resolveParamDefault($param->default));
|
||||
$node->args[$index] = new Arg($this->nodeFactory->createReprintedExpr($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
|
||||
*/
|
||||
|
@ -275,13 +275,7 @@ final class AnonymousFunctionFactory
|
||||
if (!$paramDefaultExpr instanceof Expr) {
|
||||
return null;
|
||||
}
|
||||
// reset original node, to allow the printer to re-use the expr
|
||||
$paramDefaultExpr->setAttribute(AttributeKey::ORIGINAL_NODE, null);
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($paramDefaultExpr, static function (Node $node) : Node {
|
||||
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
|
||||
return $node;
|
||||
});
|
||||
return $paramDefaultExpr;
|
||||
return $this->nodeFactory->createReprintedExpr($paramDefaultExpr);
|
||||
}
|
||||
/**
|
||||
* @param Param[] $params
|
||||
|
@ -185,7 +185,7 @@ CODE_SAMPLE
|
||||
}
|
||||
$paramDefault = $parentClassMethodParam->default;
|
||||
if ($paramDefault instanceof Expr) {
|
||||
$paramDefault = $this->resolveParamDefault($paramDefault);
|
||||
$paramDefault = $this->nodeFactory->createReprintedExpr($paramDefault);
|
||||
}
|
||||
$paramName = $this->nodeNameResolver->getName($parentClassMethodParam);
|
||||
$paramType = $this->resolveParamType($parentClassMethodParam);
|
||||
@ -197,16 +197,6 @@ CODE_SAMPLE
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* @return null|\PhpParser\Node\Identifier|\PhpParser\Node\Name|\PhpParser\Node\ComplexType
|
||||
*/
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'a24035cbbd7d86e6a45a025d60ebede4e00333f8';
|
||||
public const PACKAGE_VERSION = 'fe2c85cde9f06c2ccb0e6e7bbbb24f8def25efa9';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-10-04 18:20:32';
|
||||
public const RELEASE_DATE = '2023-10-04 18:36:04';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -42,6 +42,8 @@ use Rector\Core\Enum\ObjectReference;
|
||||
use Rector\Core\Exception\NotImplementedYetException;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\NodeDecorator\PropertyTypeDecorator;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\PostRector\ValueObject\PropertyMetadata;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
@ -70,16 +72,22 @@ final class NodeFactory
|
||||
* @var \Rector\Core\NodeDecorator\PropertyTypeDecorator
|
||||
*/
|
||||
private $propertyTypeDecorator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
|
||||
*/
|
||||
private $simpleCallableNodeTraverser;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const THIS = 'this';
|
||||
public function __construct(BuilderFactory $builderFactory, PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper, PropertyTypeDecorator $propertyTypeDecorator)
|
||||
public function __construct(BuilderFactory $builderFactory, PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper, PropertyTypeDecorator $propertyTypeDecorator, SimpleCallableNodeTraverser $simpleCallableNodeTraverser)
|
||||
{
|
||||
$this->builderFactory = $builderFactory;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
$this->staticTypeMapper = $staticTypeMapper;
|
||||
$this->propertyTypeDecorator = $propertyTypeDecorator;
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
}
|
||||
/**
|
||||
* @param string|ObjectReference::* $className
|
||||
@ -393,4 +401,14 @@ final class NodeFactory
|
||||
}
|
||||
return $exprOrVariableName;
|
||||
}
|
||||
public function createReprintedExpr(Expr $expr) : Expr
|
||||
{
|
||||
// reset original node, to allow the printer to re-use the expr
|
||||
$expr->setAttribute(AttributeKey::ORIGINAL_NODE, null);
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($expr, static function (Node $node) : Node {
|
||||
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
|
||||
return $node;
|
||||
});
|
||||
return $expr;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user