Updated Rector to commit b902afca1acb0a65d589709f0201e5edb984bacb

b902afca1a [UnusedImport] Fix removing multiple uses (#6376)
This commit is contained in:
Tomas Votruba 2024-10-12 13:01:45 +00:00
parent 5b33bdd871
commit 020433daa7
2 changed files with 12 additions and 12 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '1.2.7';
public const PACKAGE_VERSION = 'b902afca1acb0a65d589709f0201e5edb984bacb';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-10-11 18:23:19';
public const RELEASE_DATE = '2024-10-12 19:59:23';
/**
* @var int
*/

View File

@ -43,8 +43,7 @@ final class UnusedImportRemovingPostRector extends \Rector\PostRector\Rector\Abs
$hasChanged = \false;
$namespaceName = $node instanceof Namespace_ && $node->name instanceof Name ? $node->name : null;
$namesInOriginalCase = $this->resolveUsedPhpAndDocNames($node);
$namesInLowerCase = null;
// Initialized as null, lazy loaded when case in-sensitive names are needed
$namesInLowerCase = \array_map(\Closure::fromCallable('strtolower'), $namesInOriginalCase);
foreach ($node->stmts as $key => $namespaceStmt) {
if (!$namespaceStmt instanceof Use_) {
continue;
@ -54,21 +53,22 @@ final class UnusedImportRemovingPostRector extends \Rector\PostRector\Rector\Abs
$hasChanged = \true;
continue;
}
$useUse = $namespaceStmt->uses[0];
$isCaseSensitive = $namespaceStmt->type === Use_::TYPE_CONSTANT;
if ($isCaseSensitive) {
$names = $namesInOriginalCase;
} else {
if ($namesInLowerCase === null) {
$namesInLowerCase = \array_map(\Closure::fromCallable('strtolower'), $namesInOriginalCase);
}
$names = $namesInLowerCase;
}
if ($this->isUseImportUsed($useUse, $isCaseSensitive, $names, $namespaceName)) {
continue;
foreach ($namespaceStmt->uses as $useUseKey => $useUse) {
if ($this->isUseImportUsed($useUse, $isCaseSensitive, $names, $namespaceName)) {
continue;
}
unset($namespaceStmt->uses[$useUseKey]);
$hasChanged = \true;
}
if ($namespaceStmt->uses === []) {
unset($node->stmts[$key]);
}
unset($node->stmts[$key]);
$hasChanged = \true;
}
if ($hasChanged === \false) {
return null;