mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-25 09:55:28 +02:00
Updated Rector to commit 2faa19f25fc05b98515b280d38241d688909511b
2faa19f25f
[Performance][PostRector] Remove alias exists check on NameImporter called from NameImportingPostRector (#4564)
This commit is contained in:
parent
4077cf0585
commit
781ecd4a06
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
/**
|
||||
|
@ -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
|
||||
*/
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit9ff128d044597ebd8caab94554b387fa::getLoader();
|
||||
return ComposerAutoloaderInit540b41eb7793f9c7f18371f7ddc5b364::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -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;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user