mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-21 07:52:01 +02:00
Updated Rector to commit d347dd3f23c8a72a4ac9cd2a966eb72b9ed895e2
d347dd3f23
[Renaming] Skip used by trait as property promotion on RenamePropertyToMatchTypeRector (#6665)
This commit is contained in:
parent
331a8ca05e
commit
03505a62b6
@ -11,6 +11,7 @@ use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
|
||||
@ -19,8 +20,10 @@ use Rector\Naming\ParamRenamer\ParamRenamer;
|
||||
use Rector\Naming\ValueObject\ParamRename;
|
||||
use Rector\Naming\ValueObjectFactory\ParamRenameFactory;
|
||||
use Rector\Naming\VariableRenamer;
|
||||
use Rector\NodeManipulator\PropertyManipulator;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\Php\PhpVersionProvider;
|
||||
use Rector\Reflection\ReflectionResolver;
|
||||
use Rector\ValueObject\MethodName;
|
||||
use Rector\ValueObject\PhpVersionFeature;
|
||||
final class PropertyPromotionRenamer
|
||||
@ -61,7 +64,15 @@ final class PropertyPromotionRenamer
|
||||
* @readonly
|
||||
*/
|
||||
private DocBlockUpdater $docBlockUpdater;
|
||||
public function __construct(PhpVersionProvider $phpVersionProvider, MatchParamTypeExpectedNameResolver $matchParamTypeExpectedNameResolver, ParamRenameFactory $paramRenameFactory, PhpDocInfoFactory $phpDocInfoFactory, ParamRenamer $paramRenamer, \Rector\Naming\PropertyRenamer\PropertyFetchRenamer $propertyFetchRenamer, NodeNameResolver $nodeNameResolver, VariableRenamer $variableRenamer, DocBlockUpdater $docBlockUpdater)
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private ReflectionResolver $reflectionResolver;
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private PropertyManipulator $propertyManipulator;
|
||||
public function __construct(PhpVersionProvider $phpVersionProvider, MatchParamTypeExpectedNameResolver $matchParamTypeExpectedNameResolver, ParamRenameFactory $paramRenameFactory, PhpDocInfoFactory $phpDocInfoFactory, ParamRenamer $paramRenamer, \Rector\Naming\PropertyRenamer\PropertyFetchRenamer $propertyFetchRenamer, NodeNameResolver $nodeNameResolver, VariableRenamer $variableRenamer, DocBlockUpdater $docBlockUpdater, ReflectionResolver $reflectionResolver, PropertyManipulator $propertyManipulator)
|
||||
{
|
||||
$this->phpVersionProvider = $phpVersionProvider;
|
||||
$this->matchParamTypeExpectedNameResolver = $matchParamTypeExpectedNameResolver;
|
||||
@ -72,6 +83,8 @@ final class PropertyPromotionRenamer
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->variableRenamer = $variableRenamer;
|
||||
$this->docBlockUpdater = $docBlockUpdater;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
$this->propertyManipulator = $propertyManipulator;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Interface_ $classLike
|
||||
@ -86,6 +99,10 @@ final class PropertyPromotionRenamer
|
||||
if (!$constructClassMethod instanceof ClassMethod) {
|
||||
return \false;
|
||||
}
|
||||
$classReflection = $this->reflectionResolver->resolveClassReflection($classLike);
|
||||
if (!$classReflection instanceof ClassReflection) {
|
||||
return \false;
|
||||
}
|
||||
// resolve possible and existing param names
|
||||
$blockingParamNames = $this->resolveBlockingParamNames($constructClassMethod);
|
||||
foreach ($constructClassMethod->params as $param) {
|
||||
@ -104,6 +121,9 @@ final class PropertyPromotionRenamer
|
||||
if ($this->isNameSuffixed($currentParamName, $desiredPropertyName)) {
|
||||
continue;
|
||||
}
|
||||
if ($this->propertyManipulator->isUsedByTrait($classReflection, $currentParamName)) {
|
||||
continue;
|
||||
}
|
||||
$this->renameParamVarNameAndVariableUsage($classLike, $constructClassMethod, $desiredPropertyName, $param);
|
||||
$hasChanged = \true;
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Php81\Rector\New_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Enum\ObjectReference;
|
||||
@ -59,29 +60,29 @@ $enum = Enum::from($args);
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
private function refactorConstructorCallToStaticFromCall(New_ $node) : ?StaticCall
|
||||
private function refactorConstructorCallToStaticFromCall(New_ $new) : ?StaticCall
|
||||
{
|
||||
if (!$this->isObjectType($node->class, new ObjectType(self::MY_C_LABS_CLASS))) {
|
||||
if (!$this->isObjectType($new->class, new ObjectType(self::MY_C_LABS_CLASS))) {
|
||||
return null;
|
||||
}
|
||||
$classname = $this->getName($node->class);
|
||||
$classname = $this->getName($new->class);
|
||||
if (\in_array($classname, [ObjectReference::SELF, ObjectReference::STATIC], \true)) {
|
||||
$classname = ($nullsafeVariable1 = ScopeFetcher::fetch($node)->getClassReflection()) ? $nullsafeVariable1->getName() : null;
|
||||
$classname = ($nullsafeVariable1 = ScopeFetcher::fetch($new)->getClassReflection()) ? $nullsafeVariable1->getName() : null;
|
||||
}
|
||||
if ($classname === null) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isMyCLabsConstructor($node, $classname)) {
|
||||
if (!$this->isMyCLabsConstructor($new, $classname)) {
|
||||
return null;
|
||||
}
|
||||
return new StaticCall(new Name\FullyQualified($classname), self::DEFAULT_ENUM_CONSTRUCTOR, $node->args);
|
||||
return new StaticCall(new FullyQualified($classname), self::DEFAULT_ENUM_CONSTRUCTOR, $new->args);
|
||||
}
|
||||
private function isMyCLabsConstructor(New_ $node, string $classname) : bool
|
||||
private function isMyCLabsConstructor(New_ $new, string $classname) : bool
|
||||
{
|
||||
$classReflection = $this->reflectionProvider->getClass($classname);
|
||||
if (!$classReflection->hasMethod(MethodName::CONSTRUCT)) {
|
||||
return \true;
|
||||
}
|
||||
return $classReflection->getMethod(MethodName::CONSTRUCT, ScopeFetcher::fetch($node))->getDeclaringClass()->getName() === self::MY_C_LABS_CLASS;
|
||||
return $classReflection->getMethod(MethodName::CONSTRUCT, ScopeFetcher::fetch($new))->getDeclaringClass()->getName() === self::MY_C_LABS_CLASS;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '706170a2bee1e6df93e0b9789c97f7af36eb9c73';
|
||||
public const PACKAGE_VERSION = 'd347dd3f23c8a72a4ac9cd2a966eb72b9ed895e2';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2025-01-11 08:41:26';
|
||||
public const RELEASE_DATE = '2025-01-11 20:31:41';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user