From 31b96d8276955c3f0c59e812f1a1f80ef0ce60b5 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 5 Jul 2021 09:49:56 +0000 Subject: [PATCH] Updated Rector to commit 5f43d6b712538efcbcb976418c2e856de0468e3a https://github.com/rectorphp/rector-src/commit/5f43d6b712538efcbcb976418c2e856de0468e3a Make RemoveUnusedPrivateClassConstantRector use of static reflection (#384) --- docs/rector_rules_overview.md | 6 +- ...RemoveUnusedPrivateClassConstantRector.php | 51 +++----------- .../RemoveEmptyMethodCallRector.php | 25 +++---- ...aitRector.php => RemoveTraitUseRector.php} | 44 +++--------- src/Application/VersionResolver.php | 4 +- src/NodeAnalyzer/EnumAnalyzer.php | 34 +++++++++ src/NodeManipulator/ClassConstManipulator.php | 70 ++++++------------- src/NodeManipulator/ClassManipulator.php | 19 ----- src/PhpParser/AstResolver.php | 44 +++++++----- vendor/autoload.php | 2 +- vendor/composer/autoload_classmap.php | 3 +- vendor/composer/autoload_real.php | 14 ++-- vendor/composer/autoload_static.php | 11 +-- vendor/scoper-autoload.php | 10 +-- 14 files changed, 143 insertions(+), 194 deletions(-) rename rules/Removing/Rector/Class_/{RemoveTraitRector.php => RemoveTraitUseRector.php} (64%) create mode 100644 src/NodeAnalyzer/EnumAnalyzer.php diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index c7d3d2502e4..48ef7b68ecb 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -9264,15 +9264,15 @@ Remove specific traits from code - class: [`Rector\Removing\Rector\Class_\RemoveTraitRector`](../rules/Removing/Rector/Class_/RemoveTraitRector.php) ```php -use Rector\Removing\Rector\Class_\RemoveTraitRector; +use Rector\Removing\Rector\Class_\RemoveTraitUseRector; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); - $services->set(RemoveTraitRector::class) + $services->set(RemoveTraitUseRector::class) ->call('configure', [[ - RemoveTraitRector::TRAITS_TO_REMOVE => ['TraitNameToRemove'], + RemoveTraitUseRector::TRAITS_TO_REMOVE => ['TraitNameToRemove'], ]]); }; ``` diff --git a/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php b/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php index 81c69981883..66feb143786 100644 --- a/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php +++ b/rules/DeadCode/Rector/ClassConst/RemoveUnusedPrivateClassConstantRector.php @@ -4,12 +4,10 @@ declare (strict_types=1); namespace Rector\DeadCode\Rector\ClassConst; use PhpParser\Node; -use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Stmt\ClassConst; -use PhpParser\Node\Stmt\ClassLike; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; -use PHPStan\Type\ObjectType; +use Rector\Core\NodeAnalyzer\EnumAnalyzer; use Rector\Core\NodeManipulator\ClassConstManipulator; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -24,9 +22,14 @@ final class RemoveUnusedPrivateClassConstantRector extends \Rector\Core\Rector\A * @var \Rector\Core\NodeManipulator\ClassConstManipulator */ private $classConstManipulator; - public function __construct(\Rector\Core\NodeManipulator\ClassConstManipulator $classConstManipulator) + /** + * @var \Rector\Core\NodeAnalyzer\EnumAnalyzer + */ + private $enumAnalyzer; + public function __construct(\Rector\Core\NodeManipulator\ClassConstManipulator $classConstManipulator, \Rector\Core\NodeAnalyzer\EnumAnalyzer $enumAnalyzer) { $this->classConstManipulator = $classConstManipulator; + $this->enumAnalyzer = $enumAnalyzer; } public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition { @@ -62,7 +65,7 @@ CODE_SAMPLE */ public function refactor($node) : ?\PhpParser\Node { - if ($this->shouldSkip($node)) { + if ($this->shouldSkipClassConst($node)) { return null; } $scope = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE); @@ -73,30 +76,13 @@ CODE_SAMPLE if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) { return null; } - $classLike = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE); - if (!$classLike instanceof \PhpParser\Node\Stmt\ClassLike) { + if ($this->classConstManipulator->hasClassConstFetch($node, $classReflection)) { return null; } - $classObjectType = new \PHPStan\Type\ObjectType($classReflection->getName()); - /** @var ClassConstFetch[] $classConstFetches */ - $classConstFetches = $this->betterNodeFinder->findInstanceOf($classLike->stmts, \PhpParser\Node\Expr\ClassConstFetch::class); - foreach ($classConstFetches as $classConstFetch) { - if (!$this->nodeNameResolver->areNamesEqual($classConstFetch->name, $node->consts[0]->name)) { - continue; - } - $constFetchClassType = $this->nodeTypeResolver->resolve($classConstFetch->class); - // constant is used! - if ($constFetchClassType->isSuperTypeOf($classObjectType)->yes()) { - return null; - } - } $this->removeNode($node); return null; } - /** - * @param \PhpParser\Node\Stmt\ClassConst $classConst - */ - private function shouldSkip($classConst) : bool + private function shouldSkipClassConst(\PhpParser\Node\Stmt\ClassConst $classConst) : bool { if (!$classConst->isPrivate()) { return \true; @@ -104,21 +90,6 @@ CODE_SAMPLE if (\count($classConst->consts) !== 1) { return \true; } - if ($this->classConstManipulator->isEnum($classConst)) { - return \true; - } - if ($this->classConstManipulator->hasClassConstFetch($classConst)) { - return \true; - } - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classConst); - if ($phpDocInfo->hasByName('api')) { - return \true; - } - $classLike = $classConst->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE); - if ($classLike instanceof \PhpParser\Node\Stmt\ClassLike) { - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classLike); - return $phpDocInfo->hasByName('api'); - } - return \false; + return $this->enumAnalyzer->isEnumClassConst($classConst); } } diff --git a/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php b/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php index 90466dd40d0..26fd076f330 100644 --- a/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php +++ b/rules/DeadCode/Rector/MethodCall/RemoveEmptyMethodCallRector.php @@ -12,9 +12,10 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; +use PhpParser\Node\Stmt\Interface_; +use PhpParser\Node\Stmt\Trait_; use PHPStan\Analyser\Scope; -use PHPStan\Type\ObjectType; -use PHPStan\Type\ThisType; +use PHPStan\Type\TypeWithClassName; use Rector\Core\PhpParser\AstResolver; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -75,14 +76,14 @@ CODE_SAMPLE return null; } $type = $scope->getType($node->var); - if ($type instanceof \PHPStan\Type\ThisType) { - $type = $type->getStaticObjectType(); - } - if (!$type instanceof \PHPStan\Type\ObjectType) { + if (!$type instanceof \PHPStan\Type\TypeWithClassName) { return null; } - $class = $this->reflectionAstResolver->resolveClassFromObjectType($type); - if ($this->shouldSkipClassMethod($class, $node)) { + $classLike = $this->reflectionAstResolver->resolveClassFromObjectType($type); + if ($classLike === null) { + return null; + } + if ($this->shouldSkipClassMethod($classLike, $node)) { return null; } // if->cond cannot removed, it has to be replaced with false, see https://3v4l.org/U9S9i @@ -100,18 +101,18 @@ CODE_SAMPLE return $node; } /** - * @param \PhpParser\Node\Stmt\Class_|null $class + * @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Trait_|\PhpParser\Node\Stmt\Interface_ $classLike */ - private function shouldSkipClassMethod($class, \PhpParser\Node\Expr\MethodCall $methodCall) : bool + private function shouldSkipClassMethod($classLike, \PhpParser\Node\Expr\MethodCall $methodCall) : bool { - if (!$class instanceof \PhpParser\Node\Stmt\Class_) { + if (!$classLike instanceof \PhpParser\Node\Stmt\Class_) { return \true; } $methodName = $this->getName($methodCall->name); if ($methodName === null) { return \true; } - $classMethod = $class->getMethod($methodName); + $classMethod = $classLike->getMethod($methodName); if (!$classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) { return \true; } diff --git a/rules/Removing/Rector/Class_/RemoveTraitRector.php b/rules/Removing/Rector/Class_/RemoveTraitUseRector.php similarity index 64% rename from rules/Removing/Rector/Class_/RemoveTraitRector.php rename to rules/Removing/Rector/Class_/RemoveTraitUseRector.php index 9c55abafaa7..95235f902ce 100644 --- a/rules/Removing/Rector/Class_/RemoveTraitRector.php +++ b/rules/Removing/Rector/Class_/RemoveTraitUseRector.php @@ -4,19 +4,17 @@ declare (strict_types=1); namespace Rector\Removing\Rector\Class_; use PhpParser\Node; -use PhpParser\Node\Name; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Trait_; use Rector\Core\Contract\Rector\ConfigurableRectorInterface; -use Rector\Core\NodeManipulator\ClassManipulator; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\Tests\Removing\Rector\Class_\RemoveTraitRector\RemoveTraitRectorTest + * @see \Rector\Tests\Removing\Rector\Class_\RemoveTraitUseRector\RemoveTraitUseRectorTest */ -final class RemoveTraitRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface +final class RemoveTraitUseRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface { /** * @var string @@ -30,14 +28,6 @@ final class RemoveTraitRector extends \Rector\Core\Rector\AbstractRector impleme * @var string[] */ private $traitsToRemove = []; - /** - * @var \Rector\Core\NodeManipulator\ClassManipulator - */ - private $classManipulator; - public function __construct(\Rector\Core\NodeManipulator\ClassManipulator $classManipulator) - { - $this->classManipulator = $classManipulator; - } public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition { return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Remove specific traits from code', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE' @@ -65,12 +55,16 @@ CODE_SAMPLE */ public function refactor($node) : ?\PhpParser\Node { - $usedTraits = $this->classManipulator->getUsedTraits($node); - if ($usedTraits === []) { - return null; - } $this->classHasChanged = \false; - $this->removeTraits($usedTraits); + foreach ($node->getTraitUses() as $traitUse) { + foreach ($traitUse->traits as $trait) { + if (!$this->isNames($trait, $this->traitsToRemove)) { + continue; + } + $this->removeNode($traitUse); + $this->classHasChanged = \true; + } + } // invoke re-print if ($this->classHasChanged) { $node->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE, null); @@ -85,20 +79,4 @@ CODE_SAMPLE { $this->traitsToRemove = $configuration[self::TRAITS_TO_REMOVE] ?? []; } - /** - * @param Name[] $usedTraits - */ - private function removeTraits(array $usedTraits) : void - { - foreach ($usedTraits as $usedTrait) { - foreach ($this->traitsToRemove as $traitToRemove) { - if (!$this->isName($usedTrait, $traitToRemove)) { - continue; - } - $this->removeNode($usedTrait); - $this->classHasChanged = \true; - continue 2; - } - } - } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 6f95cd4a332..5c4d441b7fd 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -16,11 +16,11 @@ final class VersionResolver /** * @var string */ - public const PACKAGE_VERSION = '90b213c51914957326ef4d4f942982e772abbce4'; + public const PACKAGE_VERSION = '5f43d6b712538efcbcb976418c2e856de0468e3a'; /** * @var string */ - public const RELEASE_DATE = '2021-07-05 10:57:28'; + public const RELEASE_DATE = '2021-07-05 09:39:26'; public static function resolvePackageVersion() : string { $process = new \RectorPrefix20210705\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); diff --git a/src/NodeAnalyzer/EnumAnalyzer.php b/src/NodeAnalyzer/EnumAnalyzer.php new file mode 100644 index 00000000000..e460dc1da0d --- /dev/null +++ b/src/NodeAnalyzer/EnumAnalyzer.php @@ -0,0 +1,34 @@ +nodeNameResolver = $nodeNameResolver; + } + /** + * @see https://github.com/myclabs/php-enum#declaration + */ + public function isEnumClassConst(\PhpParser\Node\Stmt\ClassConst $classConst) : bool + { + $classLike = $classConst->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE); + if (!$classLike instanceof \PhpParser\Node\Stmt\Class_) { + return \false; + } + if ($classLike->extends === null) { + return \false; + } + return $this->nodeNameResolver->isName($classLike->extends, '*Enum'); + } +} diff --git a/src/NodeManipulator/ClassConstManipulator.php b/src/NodeManipulator/ClassConstManipulator.php index c2704162f69..2fbf1488080 100644 --- a/src/NodeManipulator/ClassConstManipulator.php +++ b/src/NodeManipulator/ClassConstManipulator.php @@ -7,10 +7,10 @@ use PhpParser\Node; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; -use PhpParser\Node\Stmt\Trait_; -use Rector\Core\PhpParser\Comparing\NodeComparator; +use PhpParser\Node\Stmt\ClassLike; +use PHPStan\Reflection\ClassReflection; +use Rector\Core\PhpParser\AstResolver; use Rector\Core\PhpParser\Node\BetterNodeFinder; -use Rector\NodeCollector\NodeCollector\NodeRepository; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; final class ClassConstManipulator @@ -19,70 +19,44 @@ final class ClassConstManipulator * @var \Rector\Core\PhpParser\Node\BetterNodeFinder */ private $betterNodeFinder; - /** - * @var \Rector\Core\NodeManipulator\ClassManipulator - */ - private $classManipulator; /** * @var \Rector\NodeNameResolver\NodeNameResolver */ private $nodeNameResolver; /** - * @var \Rector\NodeCollector\NodeCollector\NodeRepository + * @var \Rector\Core\PhpParser\AstResolver */ - private $nodeRepository; - /** - * @var \Rector\Core\PhpParser\Comparing\NodeComparator - */ - private $nodeComparator; - public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder, \Rector\Core\NodeManipulator\ClassManipulator $classManipulator, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\NodeCollector\NodeCollector\NodeRepository $nodeRepository, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator) + private $astResolver; + public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\PhpParser\AstResolver $astResolver) { $this->betterNodeFinder = $betterNodeFinder; - $this->classManipulator = $classManipulator; $this->nodeNameResolver = $nodeNameResolver; - $this->nodeRepository = $nodeRepository; - $this->nodeComparator = $nodeComparator; + $this->astResolver = $astResolver; } - public function hasClassConstFetch(\PhpParser\Node\Stmt\ClassConst $classConst) : bool + public function hasClassConstFetch(\PhpParser\Node\Stmt\ClassConst $classConst, \PHPStan\Reflection\ClassReflection $classReflection) : bool { $classLike = $classConst->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE); if (!$classLike instanceof \PhpParser\Node\Stmt\Class_) { return \false; } - $searchInNodes = [$classLike]; - $usedTraitNames = $this->classManipulator->getUsedTraits($classLike); - foreach ($usedTraitNames as $usedTraitName) { - $usedTraitName = $this->nodeRepository->findTrait((string) $usedTraitName); - if (!$usedTraitName instanceof \PhpParser\Node\Stmt\Trait_) { + foreach ($classReflection->getAncestors() as $ancestorClassReflection) { + $ancestorClass = $this->astResolver->resolveClassFromClassReflection($ancestorClassReflection, $ancestorClassReflection->getName()); + if (!$ancestorClass instanceof \PhpParser\Node\Stmt\ClassLike) { continue; } - $searchInNodes[] = $usedTraitName; - } - return (bool) $this->betterNodeFinder->find($searchInNodes, function (\PhpParser\Node $node) use($classConst) : bool { - // itself - if ($this->nodeComparator->areNodesEqual($node, $classConst)) { - return \false; + // has in class? + $isClassConstFetchFound = (bool) $this->betterNodeFinder->find($ancestorClass, function (\PhpParser\Node $node) use($classConst) : bool { + // property + static fetch + if (!$node instanceof \PhpParser\Node\Expr\ClassConstFetch) { + return \false; + } + return $this->isNameMatch($node, $classConst); + }); + if ($isClassConstFetchFound) { + return \true; } - // property + static fetch - if (!$node instanceof \PhpParser\Node\Expr\ClassConstFetch) { - return \false; - } - return $this->isNameMatch($node, $classConst); - }); - } - /** - * @see https://github.com/myclabs/php-enum#declaration - */ - public function isEnum(\PhpParser\Node\Stmt\ClassConst $classConst) : bool - { - $classLike = $classConst->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE); - if (!$classLike instanceof \PhpParser\Node\Stmt\Class_) { - return \false; } - if ($classLike->extends === null) { - return \false; - } - return $this->nodeNameResolver->isName($classLike->extends, '*Enum'); + return \false; } private function isNameMatch(\PhpParser\Node\Expr\ClassConstFetch $classConstFetch, \PhpParser\Node\Stmt\ClassConst $classConst) : bool { diff --git a/src/NodeManipulator/ClassManipulator.php b/src/NodeManipulator/ClassManipulator.php index ce31bf0c415..1adede2f4fc 100644 --- a/src/NodeManipulator/ClassManipulator.php +++ b/src/NodeManipulator/ClassManipulator.php @@ -3,12 +3,10 @@ declare (strict_types=1); namespace Rector\Core\NodeManipulator; -use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Interface_; use PhpParser\Node\Stmt\Property; -use PhpParser\Node\Stmt\Trait_; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\ObjectType; use Rector\NodeNameResolver\NodeNameResolver; @@ -33,23 +31,6 @@ final class ClassManipulator $this->nodesToRemoveCollector = $nodesToRemoveCollector; $this->reflectionProvider = $reflectionProvider; } - /** - * @deprecated - * @return array - * @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Trait_ $classLike - */ - public function getUsedTraits($classLike) : array - { - $usedTraits = []; - foreach ($classLike->getTraitUses() as $traitUse) { - foreach ($traitUse->traits as $trait) { - /** @var string $traitName */ - $traitName = $this->nodeNameResolver->getName($trait); - $usedTraits[$traitName] = $trait; - } - } - return $usedTraits; - } public function hasParentMethodOrInterface(\PHPStan\Type\ObjectType $objectType, string $methodName) : bool { if (!$this->reflectionProvider->hasClass($objectType->getClassName())) { diff --git a/src/PhpParser/AstResolver.php b/src/PhpParser/AstResolver.php index b30eb2166e1..044be40fbdb 100644 --- a/src/PhpParser/AstResolver.php +++ b/src/PhpParser/AstResolver.php @@ -7,15 +7,17 @@ use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; +use PhpParser\Node\Stmt\Interface_; +use PhpParser\Node\Stmt\Trait_; use PhpParser\NodeFinder; use PhpParser\Parser; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\Php\PhpFunctionReflection; use PHPStan\Reflection\ReflectionProvider; -use PHPStan\Type\ObjectType; use PHPStan\Type\TypeWithClassName; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\Reflection\ReflectionResolver; @@ -49,9 +51,9 @@ final class AstResolver * Parsing files is very heavy performance, so this will help to leverage it * The value can be also null, as the method might not exist in the class. * - * @var array + * @var array */ - private $classesByName = []; + private $classLikesByName = []; /** * @var \PhpParser\Parser */ @@ -100,13 +102,16 @@ final class AstResolver $this->reflectionResolver = $reflectionResolver; $this->nodeTypeResolver = $nodeTypeResolver; } - public function resolveClassFromObjectType(\PHPStan\Type\ObjectType $objectType) : ?\PhpParser\Node\Stmt\Class_ + /** + * @return \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Trait_|\PhpParser\Node\Stmt\Interface_|null + */ + public function resolveClassFromObjectType(\PHPStan\Type\TypeWithClassName $typeWithClassName) { - if (!$this->reflectionProvider->hasClass($objectType->getClassName())) { + if (!$this->reflectionProvider->hasClass($typeWithClassName->getClassName())) { return null; } - $classReflection = $this->reflectionProvider->getClass($objectType->getClassName()); - return $this->resolveClassFromClassReflection($classReflection, $objectType->getClassName()); + $classReflection = $this->reflectionProvider->getClass($typeWithClassName->getClassName()); + return $this->resolveClassFromClassReflection($classReflection, $typeWithClassName->getClassName()); } public function resolveClassMethodFromMethodReflection(\PHPStan\Reflection\MethodReflection $methodReflection) : ?\PhpParser\Node\Stmt\ClassMethod { @@ -206,39 +211,42 @@ final class AstResolver } return $this->resolveClassMethod($callerStaticType->getClassName(), $methodName); } - public function resolveClassFromClassReflection(\PHPStan\Reflection\ClassReflection $classReflection, string $className) : ?\PhpParser\Node\Stmt\Class_ + /** + * @return \PhpParser\Node\Stmt\Trait_|\PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Interface_|null + */ + public function resolveClassFromClassReflection(\PHPStan\Reflection\ClassReflection $classReflection, string $className) { if ($classReflection->isBuiltin()) { return null; } - if (isset($this->classesByName[$classReflection->getName()])) { - return $this->classesByName[$classReflection->getName()]; + if (isset($this->classLikesByName[$classReflection->getName()])) { + return $this->classLikesByName[$classReflection->getName()]; } $fileName = $classReflection->getFileName(); // probably internal class if ($fileName === \false) { // avoid parsing falsy-file again - $this->classesByName[$classReflection->getName()] = null; + $this->classLikesByName[$classReflection->getName()] = null; return null; } $fileContent = $this->smartFileSystem->readFile($fileName); $nodes = $this->parser->parse($fileContent); if ($nodes === null) { // avoid parsing falsy-file again - $this->classesByName[$classReflection->getName()] = null; + $this->classLikesByName[$classReflection->getName()] = null; return null; } - /** @var Class_[] $classes */ - $classes = $this->betterNodeFinder->findInstanceOf($nodes, \PhpParser\Node\Stmt\Class_::class); + /** @var array $classLikes */ + $classLikes = $this->betterNodeFinder->findInstanceOf($nodes, \PhpParser\Node\Stmt\ClassLike::class); $reflectionClassName = $classReflection->getName(); - foreach ($classes as $class) { + foreach ($classLikes as $classLike) { if ($reflectionClassName !== $className) { continue; } - $this->classesByName[$classReflection->getName()] = $class; - return $class; + $this->classLikesByName[$classReflection->getName()] = $classLike; + return $classLike; } - $this->classesByName[$classReflection->getName()] = null; + $this->classLikesByName[$classReflection->getName()] = null; return null; } } diff --git a/vendor/autoload.php b/vendor/autoload.php index d3fd69e2c8d..48462553aa8 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3::getLoader(); +return ComposerAutoloaderInit72b2647cd4535e261f0ad028fa7a67f7::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index e13cd5d5187..981927e3bb5 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -1837,6 +1837,7 @@ return array( 'Rector\\Core\\NodeAnalyzer\\ClassAnalyzer' => $baseDir . '/src/NodeAnalyzer/ClassAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\CompactFuncCallAnalyzer' => $baseDir . '/src/NodeAnalyzer/CompactFuncCallAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\ConstFetchAnalyzer' => $baseDir . '/src/NodeAnalyzer/ConstFetchAnalyzer.php', + 'Rector\\Core\\NodeAnalyzer\\EnumAnalyzer' => $baseDir . '/src/NodeAnalyzer/EnumAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\ParamAnalyzer' => $baseDir . '/src/NodeAnalyzer/ParamAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\PromotedPropertyParamCleaner' => $baseDir . '/src/NodeAnalyzer/PromotedPropertyParamCleaner.php', 'Rector\\Core\\NodeAnalyzer\\PropertyFetchAnalyzer' => $baseDir . '/src/NodeAnalyzer/PropertyFetchAnalyzer.php', @@ -2859,7 +2860,7 @@ return array( 'Rector\\Removing\\Rector\\ClassMethod\\ArgumentRemoverRector' => $baseDir . '/rules/Removing/Rector/ClassMethod/ArgumentRemoverRector.php', 'Rector\\Removing\\Rector\\Class_\\RemoveInterfacesRector' => $baseDir . '/rules/Removing/Rector/Class_/RemoveInterfacesRector.php', 'Rector\\Removing\\Rector\\Class_\\RemoveParentRector' => $baseDir . '/rules/Removing/Rector/Class_/RemoveParentRector.php', - 'Rector\\Removing\\Rector\\Class_\\RemoveTraitRector' => $baseDir . '/rules/Removing/Rector/Class_/RemoveTraitRector.php', + 'Rector\\Removing\\Rector\\Class_\\RemoveTraitUseRector' => $baseDir . '/rules/Removing/Rector/Class_/RemoveTraitUseRector.php', 'Rector\\Removing\\Rector\\FuncCall\\RemoveFuncCallArgRector' => $baseDir . '/rules/Removing/Rector/FuncCall/RemoveFuncCallArgRector.php', 'Rector\\Removing\\Rector\\FuncCall\\RemoveFuncCallRector' => $baseDir . '/rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php', 'Rector\\Removing\\ValueObject\\ArgumentRemover' => $baseDir . '/rules/Removing/ValueObject/ArgumentRemover.php', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index d2699333ec3..ac562d59824 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3 +class ComposerAutoloaderInit72b2647cd4535e261f0ad028fa7a67f7 { private static $loader; @@ -22,15 +22,15 @@ class ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit72b2647cd4535e261f0ad028fa7a67f7', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); - spl_autoload_unregister(array('ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit72b2647cd4535e261f0ad028fa7a67f7', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit41b2d08b01395424e71534000216a8d3::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit72b2647cd4535e261f0ad028fa7a67f7::getInitializer($loader)); } else { $classMap = require __DIR__ . '/autoload_classmap.php'; if ($classMap) { @@ -42,19 +42,19 @@ class ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit41b2d08b01395424e71534000216a8d3::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit72b2647cd4535e261f0ad028fa7a67f7::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire41b2d08b01395424e71534000216a8d3($fileIdentifier, $file); + composerRequire72b2647cd4535e261f0ad028fa7a67f7($fileIdentifier, $file); } return $loader; } } -function composerRequire41b2d08b01395424e71534000216a8d3($fileIdentifier, $file) +function composerRequire72b2647cd4535e261f0ad028fa7a67f7($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index cb38386b69e..ce852e56ce8 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit41b2d08b01395424e71534000216a8d3 +class ComposerStaticInit72b2647cd4535e261f0ad028fa7a67f7 { public static $files = array ( 'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php', @@ -2192,6 +2192,7 @@ class ComposerStaticInit41b2d08b01395424e71534000216a8d3 'Rector\\Core\\NodeAnalyzer\\ClassAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/ClassAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\CompactFuncCallAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/CompactFuncCallAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\ConstFetchAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/ConstFetchAnalyzer.php', + 'Rector\\Core\\NodeAnalyzer\\EnumAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/EnumAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\ParamAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/ParamAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\PromotedPropertyParamCleaner' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PromotedPropertyParamCleaner.php', 'Rector\\Core\\NodeAnalyzer\\PropertyFetchAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PropertyFetchAnalyzer.php', @@ -3214,7 +3215,7 @@ class ComposerStaticInit41b2d08b01395424e71534000216a8d3 'Rector\\Removing\\Rector\\ClassMethod\\ArgumentRemoverRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/ClassMethod/ArgumentRemoverRector.php', 'Rector\\Removing\\Rector\\Class_\\RemoveInterfacesRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/Class_/RemoveInterfacesRector.php', 'Rector\\Removing\\Rector\\Class_\\RemoveParentRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/Class_/RemoveParentRector.php', - 'Rector\\Removing\\Rector\\Class_\\RemoveTraitRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/Class_/RemoveTraitRector.php', + 'Rector\\Removing\\Rector\\Class_\\RemoveTraitUseRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/Class_/RemoveTraitUseRector.php', 'Rector\\Removing\\Rector\\FuncCall\\RemoveFuncCallArgRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/FuncCall/RemoveFuncCallArgRector.php', 'Rector\\Removing\\Rector\\FuncCall\\RemoveFuncCallRector' => __DIR__ . '/../..' . '/rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php', 'Rector\\Removing\\ValueObject\\ArgumentRemover' => __DIR__ . '/../..' . '/rules/Removing/ValueObject/ArgumentRemover.php', @@ -3844,9 +3845,9 @@ class ComposerStaticInit41b2d08b01395424e71534000216a8d3 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit41b2d08b01395424e71534000216a8d3::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit41b2d08b01395424e71534000216a8d3::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit41b2d08b01395424e71534000216a8d3::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit72b2647cd4535e261f0ad028fa7a67f7::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit72b2647cd4535e261f0ad028fa7a67f7::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit72b2647cd4535e261f0ad028fa7a67f7::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index 1c5aaa9686c..13f4e69f49c 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php'; if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) { spl_autoload_call('RectorPrefix20210705\AutoloadIncluder'); } -if (!class_exists('ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3', false) && !interface_exists('ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3', false) && !trait_exists('ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3', false)) { - spl_autoload_call('RectorPrefix20210705\ComposerAutoloaderInit41b2d08b01395424e71534000216a8d3'); +if (!class_exists('ComposerAutoloaderInit72b2647cd4535e261f0ad028fa7a67f7', false) && !interface_exists('ComposerAutoloaderInit72b2647cd4535e261f0ad028fa7a67f7', false) && !trait_exists('ComposerAutoloaderInit72b2647cd4535e261f0ad028fa7a67f7', false)) { + spl_autoload_call('RectorPrefix20210705\ComposerAutoloaderInit72b2647cd4535e261f0ad028fa7a67f7'); } if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) { spl_autoload_call('RectorPrefix20210705\Doctrine\Inflector\Inflector'); @@ -3308,9 +3308,9 @@ if (!function_exists('print_node')) { return \RectorPrefix20210705\print_node(...func_get_args()); } } -if (!function_exists('composerRequire41b2d08b01395424e71534000216a8d3')) { - function composerRequire41b2d08b01395424e71534000216a8d3() { - return \RectorPrefix20210705\composerRequire41b2d08b01395424e71534000216a8d3(...func_get_args()); +if (!function_exists('composerRequire72b2647cd4535e261f0ad028fa7a67f7')) { + function composerRequire72b2647cd4535e261f0ad028fa7a67f7() { + return \RectorPrefix20210705\composerRequire72b2647cd4535e261f0ad028fa7a67f7(...func_get_args()); } } if (!function_exists('parseArgs')) {