mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit f0b8af88eb08be29b5fbf18f0e26283600c2c7e6
f0b8af88eb
[AutoImport] Skip auto import on no namespace used class on auto import enabled (#5247)
This commit is contained in:
parent
340a1832bb
commit
afe2dc7944
|
@ -5,10 +5,11 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
|
|||
|
||||
use RectorPrefix202311\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\CodingStyle\ClassNameImport\ShortNameResolver;
|
||||
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
|
||||
use Rector\Core\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\Core\ValueObject\Application\File;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
/**
|
||||
* Prevents adding:
|
||||
|
@ -26,24 +27,18 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
|||
* @var \Rector\CodingStyle\ClassNameImport\ShortNameResolver
|
||||
*/
|
||||
private $shortNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Configuration\RenamedClassesDataCollector
|
||||
*/
|
||||
private $renamedClassesDataCollector;
|
||||
public function __construct(ShortNameResolver $shortNameResolver, RenamedClassesDataCollector $renamedClassesDataCollector)
|
||||
public function __construct(ShortNameResolver $shortNameResolver)
|
||||
{
|
||||
$this->shortNameResolver = $shortNameResolver;
|
||||
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
|
||||
}
|
||||
public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedObjectType, Node $node) : bool
|
||||
{
|
||||
// "new X" or "X::static()"
|
||||
/** @var array<string, string> $shortNamesToFullyQualifiedNames */
|
||||
$shortNamesToFullyQualifiedNames = $this->shortNameResolver->resolveFromFile($file);
|
||||
$removedUses = $this->renamedClassesDataCollector->getOldClasses();
|
||||
$fullyQualifiedObjectTypeShortName = $fullyQualifiedObjectType->getShortName();
|
||||
$className = $fullyQualifiedObjectType->getClassName();
|
||||
$justRenamed = $node instanceof FullyQualified && !$node->hasAttribute(AttributeKey::ORIGINAL_NAME);
|
||||
foreach ($shortNamesToFullyQualifiedNames as $shortName => $fullyQualifiedName) {
|
||||
if ($fullyQualifiedObjectTypeShortName !== $shortName) {
|
||||
$shortName = \strncmp($shortName, '\\', \strlen('\\')) === 0 ? \ltrim((string) Strings::after($shortName, '\\', -1)) : $shortName;
|
||||
|
@ -55,10 +50,7 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
|||
if ($className === $fullyQualifiedName) {
|
||||
return \false;
|
||||
}
|
||||
if (\in_array($fullyQualifiedName, $removedUses, \true)) {
|
||||
return \false;
|
||||
}
|
||||
return \strpos($fullyQualifiedName, '\\') !== \false;
|
||||
return !$justRenamed;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'e72fb255dcafb1b7e0481b1359d948692e1ff3e2';
|
||||
public const PACKAGE_VERSION = 'f0b8af88eb08be29b5fbf18f0e26283600c2c7e6';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-11-13 22:04:21';
|
||||
public const RELEASE_DATE = '2023-11-14 12:14:45';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue