mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
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:
parent
ceff1cad27
commit
5ac9de7a83
@ -5,9 +5,12 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
|
||||
|
||||
use RectorPrefix202403\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\CodingStyle\ClassNameImport\ShortNameResolver;
|
||||
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
|
||||
use Rector\Configuration\RenamedClassesDataCollector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Rector\ValueObject\Application\File;
|
||||
/**
|
||||
@ -44,6 +47,11 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
||||
$fullyQualifiedObjectTypeShortName = $fullyQualifiedObjectType->getShortName();
|
||||
$className = $fullyQualifiedObjectType->getClassName();
|
||||
$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) {
|
||||
if ($fullyQualifiedObjectTypeShortName !== $shortName) {
|
||||
$shortName = $this->cleanShortName($shortName);
|
||||
@ -55,7 +63,10 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements ClassNameImpor
|
||||
if ($className === $fullyQualifiedName) {
|
||||
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;
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '1bf3947959e10f213a04e4eb626fc2ce428add60';
|
||||
public const PACKAGE_VERSION = '685ba8a63e904c776033ba85c13f8903952e73e4';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-03-19 17:33:59';
|
||||
public const RELEASE_DATE = '2024-03-19 21:45:46';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -82,10 +82,7 @@ final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPo
|
||||
if ($node instanceof FullyQualified) {
|
||||
$result = $this->classRenamer->renameNode($node, $oldToNewClasses, $scope);
|
||||
} else {
|
||||
$phpAttributeName = $node->getAttribute(AttributeKey::PHP_ATTRIBUTE_NAME);
|
||||
if (\is_string($phpAttributeName)) {
|
||||
$result = $this->classRenamer->renameNode(new FullyQualified($phpAttributeName, $node->getAttributes()), $oldToNewClasses, $scope);
|
||||
}
|
||||
$result = $this->resolveResultWithPhpAttributeName($node, $oldToNewClasses, $scope);
|
||||
}
|
||||
if (!SimpleParameterProvider::provideBoolParameter(Option::AUTO_IMPORT_NAMES)) {
|
||||
return $result;
|
||||
@ -106,4 +103,19 @@ final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPo
|
||||
$this->renamedNameCollector->reset();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
14
vendor/composer/installed.json
vendored
14
vendor/composer/installed.json
vendored
@ -69,17 +69,17 @@
|
||||
},
|
||||
{
|
||||
"name": "composer\/pcre",
|
||||
"version": "3.1.2",
|
||||
"version_normalized": "3.1.2.0",
|
||||
"version": "3.1.3",
|
||||
"version_normalized": "3.1.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/composer\/pcre.git",
|
||||
"reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace"
|
||||
"reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/4775f35b2d70865807c89d32c8e7385b86eb0ace",
|
||||
"reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace",
|
||||
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/5b16e25a5355f1f3afdfc2f954a0a80aec4826a8",
|
||||
"reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -90,7 +90,7 @@
|
||||
"phpstan\/phpstan-strict-rules": "^1.1",
|
||||
"symfony\/phpunit-bridge": "^5"
|
||||
},
|
||||
"time": "2024-03-07T15:38:35+00:00",
|
||||
"time": "2024-03-19T10:26:25+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
@ -123,7 +123,7 @@
|
||||
],
|
||||
"support": {
|
||||
"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": [
|
||||
{
|
||||
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
6
vendor/composer/pcre/src/Preg.php
vendored
6
vendor/composer/pcre/src/Preg.php
vendored
@ -132,7 +132,7 @@ class Preg
|
||||
*
|
||||
* @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_array($subject)) {
|
||||
@ -155,7 +155,7 @@ class Preg
|
||||
*
|
||||
* @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_array($subject)) {
|
||||
@ -194,7 +194,7 @@ class Preg
|
||||
*
|
||||
* @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_array($subject)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user