Skip to content
Merged
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
5 changes: 5 additions & 0 deletions packages/CodingStyle/src/Imports/AliasUsesResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\UseUse;
use Rector\NodeTypeResolver\Node\AttributeKey;

final class AliasUsesResolver
{
Expand All @@ -23,6 +24,10 @@ public function __construct(UseImportsTraverser $useImportsTraverser)
*/
public function resolveForNode(Node $node): array
{
if (! $node instanceof Namespace_) {
$node = $node->getAttribute(AttributeKey::NAMESPACE_NODE);
}

if ($node instanceof Namespace_) {
return $this->resolveForNamespace($node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ private function shouldSkipName(Name $name, string $fullyQualifiedName): bool
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);
}

Expand All @@ -237,7 +244,6 @@ private function isShortNameAlreadyUsedForDifferentFqn(Name $name, string $short
private function canBeNameImported(Name $name): bool
{
$parentNode = $name->getAttribute(AttributeKey::PARENT_NODE);

if ($parentNode instanceof Namespace_) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function provideNamespacedClasses(): Iterator

// keep
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_trait_use.php.inc'];

Expand Down