Updated Rector to commit 685ba8a63e904c776033ba85c13f8903952e73e4

685ba8a63e [Renaming][AutoImport] Handle after change annotation to attribute with rename on AnnotationToAttributeRector + RenameClassRector with auto import (#5741)
This commit is contained in:
Tomas Votruba 2024-03-19 14:48:00 +00:00
parent ceff1cad27
commit 5ac9de7a83
6 changed files with 41 additions and 18 deletions

View File

@ -5,9 +5,12 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
use RectorPrefix202403\Nette\Utils\Strings; use RectorPrefix202403\Nette\Utils\Strings;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use Rector\CodingStyle\ClassNameImport\ShortNameResolver; use Rector\CodingStyle\ClassNameImport\ShortNameResolver;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface; use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Configuration\RenamedClassesDataCollector; use Rector\Configuration\RenamedClassesDataCollector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Rector\ValueObject\Application\File; use Rector\ValueObject\Application\File;
/** /**
@ -44,6 +47,11 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
$fullyQualifiedObjectTypeShortName = $fullyQualifiedObjectType->getShortName(); $fullyQualifiedObjectTypeShortName = $fullyQualifiedObjectType->getShortName();
$className = $fullyQualifiedObjectType->getClassName(); $className = $fullyQualifiedObjectType->getClassName();
$removedUses = $this->renamedClassesDataCollector->getOldClasses(); $removedUses = $this->renamedClassesDataCollector->getOldClasses();
$originalName = $node->getAttribute(AttributeKey::ORIGINAL_NAME);
$originalNameToAttribute = null;
if ($originalName instanceof Name && !$originalName instanceof FullyQualified && $originalName->hasAttribute(AttributeKey::PHP_ATTRIBUTE_NAME)) {
$originalNameToAttribute = $originalName->getAttribute(AttributeKey::PHP_ATTRIBUTE_NAME);
}
foreach ($shortNamesToFullyQualifiedNames as $shortName => $fullyQualifiedName) { foreach ($shortNamesToFullyQualifiedNames as $shortName => $fullyQualifiedName) {
if ($fullyQualifiedObjectTypeShortName !== $shortName) { if ($fullyQualifiedObjectTypeShortName !== $shortName) {
$shortName = $this->cleanShortName($shortName); $shortName = $this->cleanShortName($shortName);
@ -55,7 +63,10 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
if ($className === $fullyQualifiedName) { if ($className === $fullyQualifiedName) {
return \false; return \false;
} }
return !\in_array($fullyQualifiedName, $removedUses, \true); if (!\in_array($fullyQualifiedName, $removedUses, \true)) {
return $originalNameToAttribute == null || !\in_array($originalNameToAttribute, $removedUses, \true);
}
return \false;
} }
return \false; return \false;
} }

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '1bf3947959e10f213a04e4eb626fc2ce428add60'; public const PACKAGE_VERSION = '685ba8a63e904c776033ba85c13f8903952e73e4';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2024-03-19 17:33:59'; public const RELEASE_DATE = '2024-03-19 21:45:46';
/** /**
* @var int * @var int
*/ */

View File

@ -82,10 +82,7 @@ final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPo
if ($node instanceof FullyQualified) { if ($node instanceof FullyQualified) {
$result = $this->classRenamer->renameNode($node, $oldToNewClasses, $scope); $result = $this->classRenamer->renameNode($node, $oldToNewClasses, $scope);
} else { } else {
$phpAttributeName = $node->getAttribute(AttributeKey::PHP_ATTRIBUTE_NAME); $result = $this->resolveResultWithPhpAttributeName($node, $oldToNewClasses, $scope);
if (\is_string($phpAttributeName)) {
$result = $this->classRenamer->renameNode(new FullyQualified($phpAttributeName, $node->getAttributes()), $oldToNewClasses, $scope);
}
} }
if (!SimpleParameterProvider::provideBoolParameter(Option::AUTO_IMPORT_NAMES)) { if (!SimpleParameterProvider::provideBoolParameter(Option::AUTO_IMPORT_NAMES)) {
return $result; return $result;
@ -106,4 +103,19 @@ final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPo
$this->renamedNameCollector->reset(); $this->renamedNameCollector->reset();
return $nodes; return $nodes;
} }
/**
* @param array<string, string> $oldToNewClasses
*/
private function resolveResultWithPhpAttributeName(Name $name, array $oldToNewClasses, ?Scope $scope) : ?FullyQualified
{
$phpAttributeName = $name->getAttribute(AttributeKey::PHP_ATTRIBUTE_NAME);
if (\is_string($phpAttributeName)) {
$result = $this->classRenamer->renameNode(new FullyQualified($phpAttributeName, $name->getAttributes()), $oldToNewClasses, $scope);
if ($result instanceof FullyQualified) {
$result->setAttribute(AttributeKey::ORIGINAL_NAME, $name);
}
return $result;
}
return null;
}
} }

View File

@ -69,17 +69,17 @@
}, },
{ {
"name": "composer\/pcre", "name": "composer\/pcre",
"version": "3.1.2", "version": "3.1.3",
"version_normalized": "3.1.2.0", "version_normalized": "3.1.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https:\/\/github.com\/composer\/pcre.git", "url": "https:\/\/github.com\/composer\/pcre.git",
"reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace" "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/4775f35b2d70865807c89d32c8e7385b86eb0ace", "url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/5b16e25a5355f1f3afdfc2f954a0a80aec4826a8",
"reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace", "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -90,7 +90,7 @@
"phpstan\/phpstan-strict-rules": "^1.1", "phpstan\/phpstan-strict-rules": "^1.1",
"symfony\/phpunit-bridge": "^5" "symfony\/phpunit-bridge": "^5"
}, },
"time": "2024-03-07T15:38:35+00:00", "time": "2024-03-19T10:26:25+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -123,7 +123,7 @@
], ],
"support": { "support": {
"issues": "https:\/\/github.com\/composer\/pcre\/issues", "issues": "https:\/\/github.com\/composer\/pcre\/issues",
"source": "https:\/\/github.com\/composer\/pcre\/tree\/3.1.2" "source": "https:\/\/github.com\/composer\/pcre\/tree\/3.1.3"
}, },
"funding": [ "funding": [
{ {

File diff suppressed because one or more lines are too long

View File

@ -132,7 +132,7 @@ class Preg
* *
* @param-out int<0, max> $count * @param-out int<0, max> $count
*/ */
public static function replace($pattern, $replacement, $subject, int $limit = -1, int &$count = null) : string public static function replace($pattern, $replacement, $subject, int $limit = -1, ?int &$count = null) : string
{ {
if (!\is_scalar($subject)) { if (!\is_scalar($subject)) {
if (\is_array($subject)) { if (\is_array($subject)) {
@ -155,7 +155,7 @@ class Preg
* *
* @param-out int<0, max> $count * @param-out int<0, max> $count
*/ */
public static function replaceCallback($pattern, callable $replacement, $subject, int $limit = -1, int &$count = null, int $flags = 0) : string public static function replaceCallback($pattern, callable $replacement, $subject, int $limit = -1, ?int &$count = null, int $flags = 0) : string
{ {
if (!\is_scalar($subject)) { if (!\is_scalar($subject)) {
if (\is_array($subject)) { if (\is_array($subject)) {
@ -194,7 +194,7 @@ class Preg
* *
* @param-out int<0, max> $count * @param-out int<0, max> $count
*/ */
public static function replaceCallbackArray(array $pattern, $subject, int $limit = -1, int &$count = null, int $flags = 0) : string public static function replaceCallbackArray(array $pattern, $subject, int $limit = -1, ?int &$count = null, int $flags = 0) : string
{ {
if (!\is_scalar($subject)) { if (!\is_scalar($subject)) {
if (\is_array($subject)) { if (\is_array($subject)) {