forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeAlias.php
More file actions
37 lines (29 loc) · 776 Bytes
/
Copy pathTypeAlias.php
File metadata and controls
37 lines (29 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php declare(strict_types = 1);
namespace PHPStan\Type;
use PHPStan\Analyser\NameScope;
use PHPStan\PhpDoc\TypeNodeResolver;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
final class TypeAlias
{
private ?Type $resolvedType = null;
public function __construct(
private TypeNode $typeNode,
private NameScope $nameScope,
)
{
}
public static function invalid(): self
{
$self = new self(new IdentifierTypeNode('*ERROR*'), new NameScope(null, []));
$self->resolvedType = new CircularTypeAliasErrorType();
return $self;
}
public function resolve(TypeNodeResolver $typeNodeResolver): Type
{
return $this->resolvedType ??= $typeNodeResolver->resolve(
$this->typeNode,
$this->nameScope,
);
}
}