mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-28 21:53:31 +00:00
Updated Rector to commit ac072bc8af186b2c86256aa7d29e52bb608ece27
ac072bc8af
feat: add an option to skip renaming promoted property (#5457)
This commit is contained in:
parent
e61f4b3c7b
commit
bebd959a24
|
@ -99,6 +99,11 @@ final class ClassPropertyAssignToConstructorPromotionRector extends AbstractRect
|
|||
* @var string
|
||||
*/
|
||||
public const INLINE_PUBLIC = 'inline_public';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RENAME_PROPERTY = 'rename_property';
|
||||
/**
|
||||
* Default to false, which only apply changes:
|
||||
*
|
||||
|
@ -109,6 +114,11 @@ final class ClassPropertyAssignToConstructorPromotionRector extends AbstractRect
|
|||
* @var bool
|
||||
*/
|
||||
private $inlinePublic = \false;
|
||||
/**
|
||||
* Set to false will skip property promotion when parameter and property have different names.
|
||||
* @var bool
|
||||
*/
|
||||
private $renameProperty = \true;
|
||||
public function __construct(PromotedPropertyCandidateResolver $promotedPropertyCandidateResolver, VariableRenamer $variableRenamer, ParamAnalyzer $paramAnalyzer, PropertyPromotionDocBlockMerger $propertyPromotionDocBlockMerger, MakePropertyPromotionGuard $makePropertyPromotionGuard, TypeComparator $typeComparator, ReflectionResolver $reflectionResolver, PropertyPromotionRenamer $propertyPromotionRenamer, PhpDocInfoFactory $phpDocInfoFactory, StaticTypeMapper $staticTypeMapper)
|
||||
{
|
||||
$this->promotedPropertyCandidateResolver = $promotedPropertyCandidateResolver;
|
||||
|
@ -145,11 +155,12 @@ class SomeClass
|
|||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [\Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector::INLINE_PUBLIC => \false])]);
|
||||
, [\Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector::INLINE_PUBLIC => \false, \Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector::RENAME_PROPERTY => \true])]);
|
||||
}
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
$this->inlinePublic = $configuration[self::INLINE_PUBLIC] ?? (bool) \current($configuration);
|
||||
$this->inlinePublic = $configuration[self::INLINE_PUBLIC] ?? \false;
|
||||
$this->renameProperty = $configuration[self::RENAME_PROPERTY] ?? \true;
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
|
@ -185,15 +196,18 @@ CODE_SAMPLE
|
|||
if (!$this->makePropertyPromotionGuard->isLegal($node, $classReflection, $property, $param, $this->inlinePublic)) {
|
||||
continue;
|
||||
}
|
||||
$paramName = $this->getName($param);
|
||||
// rename also following calls
|
||||
$propertyName = $this->getName($property->props[0]);
|
||||
if (!$this->renameProperty && $paramName !== $propertyName) {
|
||||
continue;
|
||||
}
|
||||
// remove property from class
|
||||
$propertyStmtKey = $property->getAttribute(AttributeKey::STMT_KEY);
|
||||
unset($node->stmts[$propertyStmtKey]);
|
||||
// remove assign in constructor
|
||||
$assignStmtPosition = $promotionCandidate->getStmtPosition();
|
||||
unset($constructClassMethod->stmts[$assignStmtPosition]);
|
||||
$paramName = $this->getName($param);
|
||||
// rename also following calls
|
||||
$propertyName = $this->getName($property->props[0]);
|
||||
/** @var string $oldName */
|
||||
$oldName = $this->getName($param->var);
|
||||
$this->variableRenamer->renameVariableInFunctionLike($constructClassMethod, $oldName, $propertyName, null);
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f24b01ae0af6cdf4517fee0d74d79cc39d31f602';
|
||||
public const PACKAGE_VERSION = 'ac072bc8af186b2c86256aa7d29e52bb608ece27';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-11 22:29:41';
|
||||
public const RELEASE_DATE = '2024-01-12 00:00:19';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user