mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-19 15:45:43 +01:00
[CodingStyle] Fix ImportFullyQualifiedNamesRector for imported namespaces
This commit is contained in:
parent
b82d6dc8af
commit
1792dcc195
@ -5,6 +5,7 @@ namespace Rector\CodingStyle\Imports;
|
|||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Stmt\Namespace_;
|
use PhpParser\Node\Stmt\Namespace_;
|
||||||
use PhpParser\Node\Stmt\UseUse;
|
use PhpParser\Node\Stmt\UseUse;
|
||||||
|
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||||
|
|
||||||
final class AliasUsesResolver
|
final class AliasUsesResolver
|
||||||
{
|
{
|
||||||
@ -23,6 +24,10 @@ final class AliasUsesResolver
|
|||||||
*/
|
*/
|
||||||
public function resolveForNode(Node $node): array
|
public function resolveForNode(Node $node): array
|
||||||
{
|
{
|
||||||
|
if (! $node instanceof Namespace_) {
|
||||||
|
$node = $node->getAttribute(AttributeKey::NAMESPACE_NODE);
|
||||||
|
}
|
||||||
|
|
||||||
if ($node instanceof Namespace_) {
|
if ($node instanceof Namespace_) {
|
||||||
return $this->resolveForNamespace($node);
|
return $this->resolveForNamespace($node);
|
||||||
}
|
}
|
||||||
|
@ -221,6 +221,13 @@ CODE_SAMPLE
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($this->aliasedUses as $aliasedUse) {
|
||||||
|
// its aliased, we cannot just rename it
|
||||||
|
if (Strings::endsWith($aliasedUse, '\\' . $shortName)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->useAddingCommander->canImportBeAdded($name, $fullyQualifiedName);
|
return $this->useAddingCommander->canImportBeAdded($name, $fullyQualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +244,6 @@ CODE_SAMPLE
|
|||||||
private function canBeNameImported(Name $name): bool
|
private function canBeNameImported(Name $name): bool
|
||||||
{
|
{
|
||||||
$parentNode = $name->getAttribute(AttributeKey::PARENT_NODE);
|
$parentNode = $name->getAttribute(AttributeKey::PARENT_NODE);
|
||||||
|
|
||||||
if ($parentNode instanceof Namespace_) {
|
if ($parentNode instanceof Namespace_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rector\CodingStyle\Tests\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Request as HttpRequest;
|
||||||
|
|
||||||
|
final class KeepAlaised
|
||||||
|
{
|
||||||
|
private const SUPPORTED_HTTP_METHODS = [
|
||||||
|
HttpRequest::METHOD_GET
|
||||||
|
];
|
||||||
|
}
|
@ -36,6 +36,7 @@ final class ImportFullyQualifiedNamesRectorTest extends AbstractRectorTestCase
|
|||||||
|
|
||||||
// keep
|
// keep
|
||||||
yield [__DIR__ . '/Fixture/keep.php.inc'];
|
yield [__DIR__ . '/Fixture/keep.php.inc'];
|
||||||
|
yield [__DIR__ . '/Fixture/keep_aliased.php.inc'];
|
||||||
yield [__DIR__ . '/Fixture/keep_same_end.php.inc'];
|
yield [__DIR__ . '/Fixture/keep_same_end.php.inc'];
|
||||||
yield [__DIR__ . '/Fixture/keep_trait_use.php.inc'];
|
yield [__DIR__ . '/Fixture/keep_trait_use.php.inc'];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user