mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-27 13:13:31 +00:00
Updated Rector to commit d22e71ec0196d8f0f363845db83e064b471cb07e
d22e71ec01
Revert rename + auto import remove use tweak (#5179)
This commit is contained in:
parent
524a503444
commit
baa0c15190
|
@ -23,17 +23,23 @@ final class PostFileProcessor
|
||||||
* @var PostRectorInterface[]
|
* @var PostRectorInterface[]
|
||||||
*/
|
*/
|
||||||
private $postRectors = [];
|
private $postRectors = [];
|
||||||
public function __construct(Skipper $skipper, NameImportingPostRector $nameImportingPostRector, UseAddingPostRector $useAddingPostRector, ClassRenamingPostRector $classRenamingPostRector, UnusedImportRemovingPostRector $unusedImportRemovingPostRector)
|
public function __construct(
|
||||||
|
Skipper $skipper,
|
||||||
|
// set order here
|
||||||
|
UseAddingPostRector $useAddingPostRector,
|
||||||
|
NameImportingPostRector $nameImportingPostRector,
|
||||||
|
ClassRenamingPostRector $classRenamingPostRector,
|
||||||
|
UnusedImportRemovingPostRector $unusedImportRemovingPostRector
|
||||||
|
)
|
||||||
{
|
{
|
||||||
$this->skipper = $skipper;
|
$this->skipper = $skipper;
|
||||||
// set order here
|
|
||||||
$this->postRectors = [
|
$this->postRectors = [
|
||||||
// priority: 650
|
// priority: 650
|
||||||
$nameImportingPostRector,
|
|
||||||
// priority: 600
|
|
||||||
$useAddingPostRector,
|
|
||||||
// priority: 500
|
|
||||||
$classRenamingPostRector,
|
$classRenamingPostRector,
|
||||||
|
// priority: 600
|
||||||
|
$nameImportingPostRector,
|
||||||
|
// priority: 500
|
||||||
|
$useAddingPostRector,
|
||||||
// priority: 100
|
// priority: 100
|
||||||
$unusedImportRemovingPostRector,
|
$unusedImportRemovingPostRector,
|
||||||
];
|
];
|
||||||
|
|
|
@ -15,10 +15,7 @@ use Rector\Core\Configuration\Option;
|
||||||
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
|
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
|
||||||
use Rector\Core\Configuration\RenamedClassesDataCollector;
|
use Rector\Core\Configuration\RenamedClassesDataCollector;
|
||||||
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
|
||||||
use Rector\Core\Provider\CurrentFileProvider;
|
|
||||||
use Rector\Core\ValueObject\Application\File;
|
|
||||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||||
use Rector\PostRector\Collector\UseNodesToAddCollector;
|
|
||||||
use Rector\Renaming\NodeManipulator\ClassRenamer;
|
use Rector\Renaming\NodeManipulator\ClassRenamer;
|
||||||
final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPostRector
|
final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPostRector
|
||||||
{
|
{
|
||||||
|
@ -37,27 +34,15 @@ final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPo
|
||||||
* @var \Rector\CodingStyle\Application\UseImportsRemover
|
* @var \Rector\CodingStyle\Application\UseImportsRemover
|
||||||
*/
|
*/
|
||||||
private $useImportsRemover;
|
private $useImportsRemover;
|
||||||
/**
|
|
||||||
* @readonly
|
|
||||||
* @var \Rector\Core\Provider\CurrentFileProvider
|
|
||||||
*/
|
|
||||||
private $currentFileProvider;
|
|
||||||
/**
|
|
||||||
* @readonly
|
|
||||||
* @var \Rector\PostRector\Collector\UseNodesToAddCollector
|
|
||||||
*/
|
|
||||||
private $useNodesToAddCollector;
|
|
||||||
/**
|
/**
|
||||||
* @var \Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace|\PhpParser\Node\Stmt\Namespace_|null
|
* @var \Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace|\PhpParser\Node\Stmt\Namespace_|null
|
||||||
*/
|
*/
|
||||||
private $rootNode = null;
|
private $rootNode = null;
|
||||||
public function __construct(ClassRenamer $classRenamer, RenamedClassesDataCollector $renamedClassesDataCollector, UseImportsRemover $useImportsRemover, CurrentFileProvider $currentFileProvider, UseNodesToAddCollector $useNodesToAddCollector)
|
public function __construct(ClassRenamer $classRenamer, RenamedClassesDataCollector $renamedClassesDataCollector, UseImportsRemover $useImportsRemover)
|
||||||
{
|
{
|
||||||
$this->classRenamer = $classRenamer;
|
$this->classRenamer = $classRenamer;
|
||||||
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
|
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
|
||||||
$this->useImportsRemover = $useImportsRemover;
|
$this->useImportsRemover = $useImportsRemover;
|
||||||
$this->currentFileProvider = $currentFileProvider;
|
|
||||||
$this->useNodesToAddCollector = $useNodesToAddCollector;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param Stmt[] $nodes
|
* @param Stmt[] $nodes
|
||||||
|
@ -94,17 +79,8 @@ final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPo
|
||||||
if (!$this->rootNode instanceof FileWithoutNamespace && !$this->rootNode instanceof Namespace_) {
|
if (!$this->rootNode instanceof FileWithoutNamespace && !$this->rootNode instanceof Namespace_) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
$file = $this->currentFileProvider->getFile();
|
|
||||||
if (!$file instanceof File) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
$useImportTypes = $this->useNodesToAddCollector->getObjectImportsByFilePath($file->getFilePath());
|
|
||||||
// nothing to remove, as no replacement
|
|
||||||
if ($useImportTypes === []) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
$removedUses = $this->renamedClassesDataCollector->getOldClasses();
|
$removedUses = $this->renamedClassesDataCollector->getOldClasses();
|
||||||
$this->rootNode->stmts = $this->useImportsRemover->removeImportsFromStmts($this->rootNode->stmts, $removedUses, $useImportTypes);
|
$this->rootNode->stmts = $this->useImportsRemover->removeImportsFromStmts($this->rootNode->stmts, $removedUses);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,26 +3,22 @@
|
||||||
declare (strict_types=1);
|
declare (strict_types=1);
|
||||||
namespace Rector\CodingStyle\Application;
|
namespace Rector\CodingStyle\Application;
|
||||||
|
|
||||||
use RectorPrefix202310\Nette\Utils\Strings;
|
|
||||||
use PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
use PhpParser\Node\Stmt\Use_;
|
use PhpParser\Node\Stmt\Use_;
|
||||||
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
|
|
||||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
|
||||||
final class UseImportsRemover
|
final class UseImportsRemover
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param Stmt[] $stmts
|
* @param Stmt[] $stmts
|
||||||
* @param string[] $removedUses
|
* @param string[] $removedUses
|
||||||
* @param AliasedObjectType[]|FullyQualifiedObjectType[] $useImportTypes
|
|
||||||
* @return Stmt[]
|
* @return Stmt[]
|
||||||
*/
|
*/
|
||||||
public function removeImportsFromStmts(array $stmts, array $removedUses, array $useImportTypes) : array
|
public function removeImportsFromStmts(array $stmts, array $removedUses) : array
|
||||||
{
|
{
|
||||||
foreach ($stmts as $key => $stmt) {
|
foreach ($stmts as $key => $stmt) {
|
||||||
if (!$stmt instanceof Use_) {
|
if (!$stmt instanceof Use_) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$stmt = $this->removeUseFromUse($removedUses, $stmt, $useImportTypes);
|
$stmt = $this->removeUseFromUse($removedUses, $stmt);
|
||||||
// remove empty uses
|
// remove empty uses
|
||||||
if ($stmt->uses === []) {
|
if ($stmt->uses === []) {
|
||||||
unset($stmts[$key]);
|
unset($stmts[$key]);
|
||||||
|
@ -32,22 +28,13 @@ final class UseImportsRemover
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param string[] $removedUses
|
* @param string[] $removedUses
|
||||||
* @param AliasedObjectType[]|FullyQualifiedObjectType[] $useImportTypes
|
|
||||||
*/
|
*/
|
||||||
private function removeUseFromUse(array $removedUses, Use_ $use, array $useImportTypes) : Use_
|
private function removeUseFromUse(array $removedUses, Use_ $use) : Use_
|
||||||
{
|
{
|
||||||
foreach ($use->uses as $usesKey => $useUse) {
|
foreach ($use->uses as $usesKey => $useUse) {
|
||||||
$useName = $useUse->name->toString();
|
$useName = $useUse->name->toString();
|
||||||
if (!\in_array($useName, $removedUses, \true)) {
|
if (\in_array($useName, $removedUses, \true)) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$lastUseName = Strings::after($useName, '\\', -1);
|
|
||||||
foreach ($useImportTypes as $useImportType) {
|
|
||||||
$className = $useImportType instanceof AliasedObjectType ? $useImportType->getFullyQualifiedName() : $useImportType->getClassName();
|
|
||||||
if ($className === $useName || Strings::after($className, '\\', -1) === $lastUseName) {
|
|
||||||
unset($use->uses[$usesKey]);
|
unset($use->uses[$usesKey]);
|
||||||
continue 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $use;
|
return $use;
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
declare (strict_types=1);
|
declare (strict_types=1);
|
||||||
namespace Rector\DeadCode\Rector\If_;
|
namespace Rector\DeadCode\Rector\If_;
|
||||||
|
|
||||||
|
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Expr;
|
use PhpParser\Node\Expr;
|
||||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
|
||||||
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
|
||||||
use PhpParser\Node\Expr\Variable;
|
use PhpParser\Node\Expr\Variable;
|
||||||
use PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = 'cd0c14e144f4d4ef35b4cd42751981c40023879a';
|
public const PACKAGE_VERSION = 'd22e71ec0196d8f0f363845db83e064b471cb07e';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2023-10-16 11:15:50';
|
public const RELEASE_DATE = '2023-10-16 07:36:04';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user