Skip to content

Commit

Permalink
Updated Rector to commit f0b8af88eb08be29b5fbf18f0e26283600c2c7e6
Browse files Browse the repository at this point in the history
rectorphp/rector-src@f0b8af8 [AutoImport] Skip auto import on no namespace used class on auto import enabled (#5247)
  • Loading branch information
TomasVotruba committed Nov 14, 2023
1 parent 340a183 commit afe2dc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

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:
Expand All @@ -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;
Expand All @@ -55,10 +50,7 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
if ($className === $fullyQualifiedName) {
return \false;
}
if (\in_array($fullyQualifiedName, $removedUses, \true)) {
return \false;
}
return \strpos($fullyQualifiedName, '\\') !== \false;
return !$justRenamed;
}
return \false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit afe2dc7

Please sign in to comment.