diff --git a/packages/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php b/packages/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php index e1c1419cf0a..14f54d0f8c1 100644 --- a/packages/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php +++ b/packages/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php @@ -14,8 +14,6 @@ use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey; -use Rector\Core\Configuration\Option; -use Rector\Core\Configuration\Parameter\SimpleParameterProvider; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Naming\Naming\UseImportsResolver; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -80,12 +78,6 @@ final class ClassRenamePhpDocNodeVisitor extends AbstractPhpDocNodeVisitor $identifier = clone $node; $identifier->name = $this->resolveNamespacedName($identifier, $currentPhpNode, $node->name); $staticType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($identifier, $currentPhpNode); - $shouldImport = SimpleParameterProvider::provideBoolParameter(Option::AUTO_IMPORT_NAMES); - $isNoNamespacedName = \strncmp($identifier->name, '\\', \strlen('\\')) !== 0 && \substr_count($identifier->name, '\\') === 0; - // tweak overlapped import + rename - if ($shouldImport && $isNoNamespacedName) { - return null; - } // make sure to compare FQNs $objectType = $this->expandShortenedObjectType($staticType); foreach ($this->oldToNewTypes as $oldToNewType) { diff --git a/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/FullyQualifiedNameClassNameImportSkipVoter.php b/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/FullyQualifiedNameClassNameImportSkipVoter.php index 19cfac0f0a7..4f4f4c55507 100644 --- a/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/FullyQualifiedNameClassNameImportSkipVoter.php +++ b/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/FullyQualifiedNameClassNameImportSkipVoter.php @@ -3,6 +3,7 @@ declare (strict_types=1); namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter; +use RectorPrefix202311\Nette\Utils\Strings; use PhpParser\Node; use Rector\CodingStyle\ClassNameImport\ShortNameResolver; use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface; @@ -41,14 +42,23 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor /** @var array $shortNamesToFullyQualifiedNames */ $shortNamesToFullyQualifiedNames = $this->shortNameResolver->resolveFromFile($file); $removedUses = $this->renamedClassesDataCollector->getOldClasses(); + $fullyQualifiedObjectTypeShortName = $fullyQualifiedObjectType->getShortName(); + $className = $fullyQualifiedObjectType->getClassName(); foreach ($shortNamesToFullyQualifiedNames as $shortName => $fullyQualifiedName) { - if ($fullyQualifiedObjectType->getShortName() !== $shortName) { + if ($fullyQualifiedObjectTypeShortName !== $shortName) { + $shortName = \strncmp($shortName, '\\', \strlen('\\')) === 0 ? \ltrim((string) Strings::after($shortName, '\\', -1)) : $shortName; + } + if ($fullyQualifiedObjectTypeShortName !== $shortName) { continue; } + $fullyQualifiedName = \ltrim($fullyQualifiedName, '\\'); + if ($className === $fullyQualifiedName) { + return \false; + } if (\in_array($fullyQualifiedName, $removedUses, \true)) { - continue; + return \false; } - return $fullyQualifiedObjectType->getClassName() !== $fullyQualifiedName; + return \strpos($fullyQualifiedName, '\\') !== \false; } return \false; } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index f200a770783..8a378e0a583 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 = 'f9de5d311e7e69d1ad2cb5f3087970d8b9335920'; + public const PACKAGE_VERSION = '2fac959116e4f50471422e5e5c9eaca3163e6667'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-11-02 10:16:59'; + public const RELEASE_DATE = '2023-11-03 15:36:34'; /** * @var int */