Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc #1154

Merged
merged 1 commit into from
Nov 5, 2021
Merged

misc #1154

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
}
2 changes: 1 addition & 1 deletion packages/PostRector/Collector/UseNodesToAddCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions packages/PostRector/Rector/NameImportingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class BeLocalClass
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class SomeAbstractTestCase
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ final class RemoveUnusedAliasRectorTest extends AbstractRectorTestCase
*/
public function test(SmartFileInfo $fileInfo): void
{
dump($fileInfo->getRealPath());

$this->doTestFileInfo($fileInfo);
}

Expand Down
2 changes: 1 addition & 1 deletion rules/CodingStyle/Node/NameImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions rules/CodingStyle/Rector/Use_/RemoveUnusedAliasRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down