Skip to content

Commit

Permalink
[PHPStanStaticTypeMapper] Fix IntersectionTypeMapper to make ObjectTy…
Browse files Browse the repository at this point in the history
…pe have FQCN (#4598)

* [PHPStanStaticTypeMapper] Fix IntersectionTypeMapper to make ObjectType have FQCN

* [PHPStanStaticTypeMapper] Fix IntersectionTypeMapper to make ObjectType have FQCN

* remove static

* fix

* fix

* fix
  • Loading branch information
samsonasik committed Jul 25, 2023
1 parent 7784494 commit 3c82c6e
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Node as AstNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\IntersectionType;
Expand All @@ -15,6 +17,7 @@
use PHPStan\Type\Type;
use Rector\Core\Php\PhpVersionProvider;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Symfony\Contracts\Service\Attribute\Required;
Expand Down Expand Up @@ -51,7 +54,23 @@ public function getNodeClass(): string
*/
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
{
return $type->toPhpDocNode();
$typeNode = $type->toPhpDocNode();

$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable(
$typeNode,
'',
static function (AstNode $astNode): ?IdentifierTypeNode {
if ($astNode instanceof IdentifierTypeNode) {
$astNode->name = '\\' . $astNode->name;
return $astNode;
}

return null;
}
);

return $typeNode;
}

/**
Expand Down

0 comments on commit 3c82c6e

Please sign in to comment.