diff --git a/packages/NodeTypeResolver/PhpDocNodeVisitor/NameImportingPhpDocNodeVisitor.php b/packages/NodeTypeResolver/PhpDocNodeVisitor/NameImportingPhpDocNodeVisitor.php index fa973bcc201..81ceddb1c67 100644 --- a/packages/NodeTypeResolver/PhpDocNodeVisitor/NameImportingPhpDocNodeVisitor.php +++ b/packages/NodeTypeResolver/PhpDocNodeVisitor/NameImportingPhpDocNodeVisitor.php @@ -116,10 +116,8 @@ final class NameImportingPhpDocNodeVisitor extends AbstractPhpDocNodeVisitor } $newNode = new IdentifierTypeNode($fullyQualifiedObjectType->getShortName()); // should skip because its already used - if ($this->useNodesToAddCollector->isShortImported($file, $fullyQualifiedObjectType)) { - if (!$this->useNodesToAddCollector->isImportShortable($file, $fullyQualifiedObjectType)) { - return null; - } + if ($this->useNodesToAddCollector->isShortImported($file, $fullyQualifiedObjectType) && !$this->useNodesToAddCollector->isImportShortable($file, $fullyQualifiedObjectType)) { + return null; } if ($this->shouldImport($newNode, $identifierTypeNode, $fullyQualifiedObjectType)) { $this->useNodesToAddCollector->addUseImport($fullyQualifiedObjectType); diff --git a/packages/PostRector/Rector/NameImportingPostRector.php b/packages/PostRector/Rector/NameImportingPostRector.php index 118017e4d7d..fd7212bf615 100644 --- a/packages/PostRector/Rector/NameImportingPostRector.php +++ b/packages/PostRector/Rector/NameImportingPostRector.php @@ -147,7 +147,7 @@ CODE_SAMPLE if ($nameInUse instanceof Name) { return $nameInUse; } - return $this->nameImporter->importName($name, $file, $currentUses); + return $this->nameImporter->importName($name, $file); } return null; } diff --git a/rules/CodingStyle/Node/NameImporter.php b/rules/CodingStyle/Node/NameImporter.php index 5600f8cbb8b..38ea6f7c3be 100644 --- a/rules/CodingStyle/Node/NameImporter.php +++ b/rules/CodingStyle/Node/NameImporter.php @@ -4,9 +4,6 @@ declare (strict_types=1); namespace Rector\CodingStyle\Node; use PhpParser\Node\Name; -use PhpParser\Node\Stmt\GroupUse; -use PhpParser\Node\Stmt\Use_; -use Rector\CodingStyle\ClassNameImport\AliasUsesResolver; use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper; use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Parameter\SimpleParameterProvider; @@ -17,11 +14,6 @@ use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; final class NameImporter { - /** - * @readonly - * @var \Rector\CodingStyle\ClassNameImport\AliasUsesResolver - */ - private $aliasUsesResolver; /** * @readonly * @var \Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper @@ -37,21 +29,13 @@ final class NameImporter * @var \Rector\PostRector\Collector\UseNodesToAddCollector */ private $useNodesToAddCollector; - /** - * @var string[] - */ - private $aliasedUses = []; - public function __construct(AliasUsesResolver $aliasUsesResolver, ClassNameImportSkipper $classNameImportSkipper, StaticTypeMapper $staticTypeMapper, UseNodesToAddCollector $useNodesToAddCollector) + public function __construct(ClassNameImportSkipper $classNameImportSkipper, StaticTypeMapper $staticTypeMapper, UseNodesToAddCollector $useNodesToAddCollector) { - $this->aliasUsesResolver = $aliasUsesResolver; $this->classNameImportSkipper = $classNameImportSkipper; $this->staticTypeMapper = $staticTypeMapper; $this->useNodesToAddCollector = $useNodesToAddCollector; } - /** - * @param Use_[]|GroupUse[] $uses - */ - public function importName(Name $name, File $file, array $uses) : ?Name + public function importName(Name $name, File $file) : ?Name { if ($this->shouldSkipName($name)) { return null; @@ -60,10 +44,7 @@ final class NameImporter if (!$staticType instanceof FullyQualifiedObjectType) { return null; } - $className = $staticType->getClassName(); - // class has \, no need to search in aliases, mark aliasedUses as empty - $this->aliasedUses = \strpos($className, '\\') !== \false ? [] : $this->aliasUsesResolver->resolveFromStmts($uses); - return $this->importNameAndCollectNewUseStatement($file, $name, $staticType, $className); + return $this->importNameAndCollectNewUseStatement($file, $name, $staticType); } private function shouldSkipName(Name $name) : bool { @@ -92,7 +73,7 @@ final class NameImporter } return \false; } - private function importNameAndCollectNewUseStatement(File $file, Name $name, FullyQualifiedObjectType $fullyQualifiedObjectType, string $className) : ?Name + private function importNameAndCollectNewUseStatement(File $file, Name $name, FullyQualifiedObjectType $fullyQualifiedObjectType) : ?Name { // the same end is already imported → skip if ($this->classNameImportSkipper->shouldSkipNameForFullyQualifiedObjectType($file, $name, $fullyQualifiedObjectType)) { @@ -105,15 +86,6 @@ final class NameImporter return null; } $this->addUseImport($file, $name, $fullyQualifiedObjectType); - if ($this->aliasedUses === []) { - return $fullyQualifiedObjectType->getShortNameNode(); - } - // possibly aliased - foreach ($this->aliasedUses as $aliasedUse) { - if ($className === $aliasedUse) { - return null; - } - } return $fullyQualifiedObjectType->getShortNameNode(); } /** diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index aca2ad828a6..975ff361e11 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'd17ef04059a72836772e44bd9664ee64fbc1f3c0'; + public const PACKAGE_VERSION = '2faa19f25fc05b98515b280d38241d688909511b'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-07-21 15:08:54'; + public const RELEASE_DATE = '2023-07-21 15:35:03'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index b3fe38c7af4..c8fa847112e 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit9ff128d044597ebd8caab94554b387fa::getLoader(); +return ComposerAutoloaderInit540b41eb7793f9c7f18371f7ddc5b364::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 67b4ac52daf..3146795b8d4 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit9ff128d044597ebd8caab94554b387fa +class ComposerAutoloaderInit540b41eb7793f9c7f18371f7ddc5b364 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInit9ff128d044597ebd8caab94554b387fa return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit9ff128d044597ebd8caab94554b387fa', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit540b41eb7793f9c7f18371f7ddc5b364', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit9ff128d044597ebd8caab94554b387fa', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit540b41eb7793f9c7f18371f7ddc5b364', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit9ff128d044597ebd8caab94554b387fa::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit540b41eb7793f9c7f18371f7ddc5b364::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInit9ff128d044597ebd8caab94554b387fa::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit540b41eb7793f9c7f18371f7ddc5b364::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index b83d2c5d9ba..b6d3f2a780d 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit9ff128d044597ebd8caab94554b387fa +class ComposerStaticInit540b41eb7793f9c7f18371f7ddc5b364 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3023,9 +3023,9 @@ class ComposerStaticInit9ff128d044597ebd8caab94554b387fa public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit9ff128d044597ebd8caab94554b387fa::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit9ff128d044597ebd8caab94554b387fa::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit9ff128d044597ebd8caab94554b387fa::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit540b41eb7793f9c7f18371f7ddc5b364::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit540b41eb7793f9c7f18371f7ddc5b364::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit540b41eb7793f9c7f18371f7ddc5b364::$classMap; }, null, ClassLoader::class); }