mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 889372f62a584ca43402eced083b99e2ffbe6784
889372f62a
[AutoImport][Renaming] Handle same last name no namespace just renamed auto import (#5248)
This commit is contained in:
parent
afe2dc7944
commit
83b81fcc4e
|
@ -5,11 +5,10 @@ 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:
|
||||
|
@ -27,9 +26,15 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
|||
* @var \Rector\CodingStyle\ClassNameImport\ShortNameResolver
|
||||
*/
|
||||
private $shortNameResolver;
|
||||
public function __construct(ShortNameResolver $shortNameResolver)
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Configuration\RenamedClassesDataCollector
|
||||
*/
|
||||
private $renamedClassesDataCollector;
|
||||
public function __construct(ShortNameResolver $shortNameResolver, RenamedClassesDataCollector $renamedClassesDataCollector)
|
||||
{
|
||||
$this->shortNameResolver = $shortNameResolver;
|
||||
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
|
||||
}
|
||||
public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedObjectType, Node $node) : bool
|
||||
{
|
||||
|
@ -38,10 +43,10 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
|||
$shortNamesToFullyQualifiedNames = $this->shortNameResolver->resolveFromFile($file);
|
||||
$fullyQualifiedObjectTypeShortName = $fullyQualifiedObjectType->getShortName();
|
||||
$className = $fullyQualifiedObjectType->getClassName();
|
||||
$justRenamed = $node instanceof FullyQualified && !$node->hasAttribute(AttributeKey::ORIGINAL_NAME);
|
||||
$removedUses = $this->renamedClassesDataCollector->getOldClasses();
|
||||
foreach ($shortNamesToFullyQualifiedNames as $shortName => $fullyQualifiedName) {
|
||||
if ($fullyQualifiedObjectTypeShortName !== $shortName) {
|
||||
$shortName = \strncmp($shortName, '\\', \strlen('\\')) === 0 ? \ltrim((string) Strings::after($shortName, '\\', -1)) : $shortName;
|
||||
$shortName = $this->cleanShortName($shortName);
|
||||
}
|
||||
if ($fullyQualifiedObjectTypeShortName !== $shortName) {
|
||||
continue;
|
||||
|
@ -50,8 +55,12 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
|||
if ($className === $fullyQualifiedName) {
|
||||
return \false;
|
||||
}
|
||||
return !$justRenamed;
|
||||
return !\in_array($fullyQualifiedName, $removedUses, \true);
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function cleanShortName(string $shortName) : string
|
||||
{
|
||||
return \strncmp($shortName, '\\', \strlen('\\')) === 0 ? \ltrim((string) Strings::after($shortName, '\\', -1)) : $shortName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use PhpParser\Node\FunctionLike;
|
|||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Core\Configuration\RenamedClassesDataCollector;
|
||||
|
@ -71,10 +72,10 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Name::class, Property::class, FunctionLike::class, Expression::class, ClassLike::class, Namespace_::class];
|
||||
return [Name::class, Property::class, FunctionLike::class, Expression::class, ClassLike::class, Namespace_::class, If_::class];
|
||||
}
|
||||
/**
|
||||
* @param FunctionLike|Name|ClassLike|Expression|Namespace_|Property $node
|
||||
* @param FunctionLike|Name|ClassLike|Expression|Namespace_|Property|If_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f0b8af88eb08be29b5fbf18f0e26283600c2c7e6';
|
||||
public const PACKAGE_VERSION = '889372f62a584ca43402eced083b99e2ffbe6784';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-11-14 12:14:45';
|
||||
public const RELEASE_DATE = '2023-11-14 18:44:59';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue