Skip to content

Commit

Permalink
Closes #2468
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jun 10, 2022
1 parent 9110446 commit 088c182
Showing 1 changed file with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpParser\Node as PhpParserNode;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_;
Expand All @@ -25,7 +24,6 @@
use Rector\NodeTypeResolver\ValueObject\OldToNewType;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
use Symplify\Astral\PhpDocParser\PhpDocNodeVisitor\AbstractPhpDocNodeVisitor;

Expand Down Expand Up @@ -68,20 +66,11 @@ public function enterNode(Node $node): ?Node
return null;
}

$previousNode = $phpParserNode->getAttribute(AttributeKey::PREVIOUS_NODE);
if ($previousNode instanceof FullyQualified) {
return null;
}

$identifier = clone $node;
$namespacedName = $this->resolveNamespacedName($phpParserNode, $node->name);
$identifier->name = $namespacedName;
$staticType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($identifier, $phpParserNode);

if ($staticType instanceof AliasedObjectType) {
return null;
}

// make sure to compare FQNs
$objectType = $this->expandShortenedObjectType($staticType);

Expand Down Expand Up @@ -143,13 +132,13 @@ private function resolveNamespacedName(PhpParserNode $phpParserNode, string $nam
return $namespaceName . '\\' . $name;
}

return $this->resolveNamefromUse($uses, $name);
return $this->resolveNamefromUse($uses, $name, $namespaceName . '\\');
}

/**
* @param Use_[]|GroupUse[] $uses
*/
private function resolveNamefromUse(array $uses, string $name): string
private function resolveNamefromUse(array $uses, string $name, ?string $namespaceName = null): string
{
foreach ($uses as $use) {
$prefix = $this->useImportsResolver->resolvePrefix($use);
Expand All @@ -166,7 +155,7 @@ private function resolveNamefromUse(array $uses, string $name): string
}
}

return $name;
return $namespaceName . $name;
}

private function expandShortenedObjectType(Type $type): ObjectType|Type
Expand Down

0 comments on commit 088c182

Please sign in to comment.