From cf516201b8a51b08852e5f6e2c9c60cd3cd48992 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 5 Nov 2021 12:09:40 +0100 Subject: [PATCH] misc (#1154) --- .../NodeAnalyzer/UseAnalyzer/UseAnalyzerTest.php | 7 +++++-- packages/PostRector/Collector/UseNodesToAddCollector.php | 2 +- packages/PostRector/Rector/NameImportingPostRector.php | 4 ++-- .../Source/BeLocalClass.php | 1 - .../Source/SomeAbstractTestCase.php | 1 - .../RemoveUnusedAliasRectorTest.php | 2 -- rules/CodingStyle/Node/NameImporter.php | 2 +- rules/CodingStyle/Rector/Use_/RemoveUnusedAliasRector.php | 4 ---- 8 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages-tests/NameImporting/NodeAnalyzer/UseAnalyzer/UseAnalyzerTest.php b/packages-tests/NameImporting/NodeAnalyzer/UseAnalyzer/UseAnalyzerTest.php index 0adcb001864..62376b7a27d 100644 --- a/packages-tests/NameImporting/NodeAnalyzer/UseAnalyzer/UseAnalyzerTest.php +++ b/packages-tests/NameImporting/NodeAnalyzer/UseAnalyzer/UseAnalyzerTest.php @@ -11,6 +11,7 @@ use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\UseUse; use Rector\NameImporting\NodeAnalyzer\UseAnalyzer; use Rector\NameImporting\ValueObject\NameAndParent; use Rector\Testing\PHPUnit\AbstractTestCase; @@ -82,15 +83,17 @@ public function provideData(): Iterator 'BaseKernel', 0, new Identifier('BaseKernel'), - Node\Stmt\UseUse::class, + UseUse::class, ]; + yield [ __DIR__ . '/Fixture/use_import.php.inc', 'BaseInterface', 0, new Identifier('BaseInterface'), - Node\Stmt\UseUse::class, + UseUse::class, ]; + yield [__DIR__ . '/Fixture/use_import.php.inc', 'SomeClass', 0, new Identifier('SomeClass'), Class_::class]; } } diff --git a/packages/PostRector/Collector/UseNodesToAddCollector.php b/packages/PostRector/Collector/UseNodesToAddCollector.php index 55cd579ebbb..b9669cd339a 100644 --- a/packages/PostRector/Collector/UseNodesToAddCollector.php +++ b/packages/PostRector/Collector/UseNodesToAddCollector.php @@ -44,7 +44,7 @@ public function addUseImport(FullyQualifiedObjectType | AliasedObjectType $objec $this->useImportTypesInFilePath[$smartFileInfo->getRealPath()][] = $objectType; } - public function addFunctionUseImport(Node $node, FullyQualifiedObjectType $fullyQualifiedObjectType): void + public function addFunctionUseImport(FullyQualifiedObjectType $fullyQualifiedObjectType): void { $file = $this->currentFileProvider->getFile(); $smartFileInfo = $file->getSmartFileInfo(); diff --git a/packages/PostRector/Rector/NameImportingPostRector.php b/packages/PostRector/Rector/NameImportingPostRector.php index 1a9c818bb88..2f0aa7a678c 100644 --- a/packages/PostRector/Rector/NameImportingPostRector.php +++ b/packages/PostRector/Rector/NameImportingPostRector.php @@ -111,7 +111,7 @@ private function processNodeName(Name $name, File $file): ?Node /** @var Use_[] $currentUses */ $currentUses = $this->betterNodeFinder->findInstanceOf($file->getNewStmts(), Use_::class); - if ($this->shouldImportName($name, $file, $currentUses)) { + if ($this->shouldImportName($name, $currentUses)) { return $this->nameImporter->importName($name, $file, $currentUses); } @@ -121,7 +121,7 @@ private function processNodeName(Name $name, File $file): ?Node /** * @param Use_[] $currentUses */ - private function shouldImportName(Name $name, File $file, array $currentUses): bool + private function shouldImportName(Name $name, array $currentUses): bool { if (substr_count($name->toCodeString(), '\\') <= 1) { return true; diff --git a/rules-tests/CodingStyle/Rector/MethodCall/PreferThisOrSelfMethodCallRector/Source/BeLocalClass.php b/rules-tests/CodingStyle/Rector/MethodCall/PreferThisOrSelfMethodCallRector/Source/BeLocalClass.php index f28c04b9fd2..2ae7a633b80 100644 --- a/rules-tests/CodingStyle/Rector/MethodCall/PreferThisOrSelfMethodCallRector/Source/BeLocalClass.php +++ b/rules-tests/CodingStyle/Rector/MethodCall/PreferThisOrSelfMethodCallRector/Source/BeLocalClass.php @@ -6,5 +6,4 @@ class BeLocalClass { - } diff --git a/rules-tests/CodingStyle/Rector/MethodCall/PreferThisOrSelfMethodCallRector/Source/SomeAbstractTestCase.php b/rules-tests/CodingStyle/Rector/MethodCall/PreferThisOrSelfMethodCallRector/Source/SomeAbstractTestCase.php index b2542c7b259..37ed1ac6389 100644 --- a/rules-tests/CodingStyle/Rector/MethodCall/PreferThisOrSelfMethodCallRector/Source/SomeAbstractTestCase.php +++ b/rules-tests/CodingStyle/Rector/MethodCall/PreferThisOrSelfMethodCallRector/Source/SomeAbstractTestCase.php @@ -6,5 +6,4 @@ abstract class SomeAbstractTestCase { - } diff --git a/rules-tests/CodingStyle/Rector/Use_/RemoveUnusedAliasRector/RemoveUnusedAliasRectorTest.php b/rules-tests/CodingStyle/Rector/Use_/RemoveUnusedAliasRector/RemoveUnusedAliasRectorTest.php index 9e79c385c38..10cab2e24f7 100644 --- a/rules-tests/CodingStyle/Rector/Use_/RemoveUnusedAliasRector/RemoveUnusedAliasRectorTest.php +++ b/rules-tests/CodingStyle/Rector/Use_/RemoveUnusedAliasRector/RemoveUnusedAliasRectorTest.php @@ -15,8 +15,6 @@ final class RemoveUnusedAliasRectorTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - dump($fileInfo->getRealPath()); - $this->doTestFileInfo($fileInfo); } diff --git a/rules/CodingStyle/Node/NameImporter.php b/rules/CodingStyle/Node/NameImporter.php index 578442e97d2..54df1461831 100644 --- a/rules/CodingStyle/Node/NameImporter.php +++ b/rules/CodingStyle/Node/NameImporter.php @@ -179,7 +179,7 @@ private function addUseImport(File $file, Name $name, FullyQualifiedObjectType $ $parentNode = $name->getAttribute(AttributeKey::PARENT_NODE); if ($parentNode instanceof FuncCall) { - $this->useNodesToAddCollector->addFunctionUseImport($name, $fullyQualifiedObjectType); + $this->useNodesToAddCollector->addFunctionUseImport($fullyQualifiedObjectType); } else { $this->useNodesToAddCollector->addUseImport($fullyQualifiedObjectType); } diff --git a/rules/CodingStyle/Rector/Use_/RemoveUnusedAliasRector.php b/rules/CodingStyle/Rector/Use_/RemoveUnusedAliasRector.php index d98b6423480..93cffe091e5 100644 --- a/rules/CodingStyle/Rector/Use_/RemoveUnusedAliasRector.php +++ b/rules/CodingStyle/Rector/Use_/RemoveUnusedAliasRector.php @@ -100,10 +100,6 @@ public function refactor(Node $node): ?Node } $this->resolvedNamesAndParentsByShortName = $this->useAnalyzer->resolveUsedNameNodes($searchNode); - - dump(count($this->resolvedNamesAndParentsByShortName)); - die; - $this->resolvedDocPossibleAliases = $this->docAliasResolver->resolve($searchNode); $this->useNamesAliasToName = $this->useNameAliasToNameResolver->resolve($this->file);