Skip to content

Commit

Permalink
Updated Rector to commit 889372f62a584ca43402eced083b99e2ffbe6784
Browse files Browse the repository at this point in the history
rectorphp/rector-src@889372f [AutoImport][Renaming] Handle same last name no namespace just renamed auto import (#5248)
  • Loading branch information
TomasVotruba committed Nov 14, 2023
1 parent afe2dc7 commit 83b81fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

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 @@ -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
{
Expand All @@ -38,10 +43,10 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
$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;
Expand All @@ -50,8 +55,12 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
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;
}
}
5 changes: 3 additions & 2 deletions rules/Renaming/Rector/Name/RenameClassRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -71,10 +72,10 @@ function someFunction(SomeNewClass $someOldClass): SomeNewClass
*/
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
{
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 = '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
*/
Expand Down

0 comments on commit 83b81fc

Please sign in to comment.