/
TTemplateKeyOf.php
94 lines (81 loc) · 2.06 KB
/
TTemplateKeyOf.php
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Psalm\Type\Atomic;
use Psalm\Codebase;
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
use Psalm\Internal\Type\TemplateResult;
use Psalm\Type\Atomic;
use Psalm\Type\Union;
/**
* Represents the type used when using TKeyOf when the type of the array is a template
*/
final class TTemplateKeyOf extends Atomic
{
/**
* @var string
*/
public $param_name;
/**
* @var string
*/
public $defining_class;
/**
* @var Union
*/
public $as;
public function __construct(
string $param_name,
string $defining_class,
Union $as
) {
$this->param_name = $param_name;
$this->defining_class = $defining_class;
$this->as = $as;
}
public function getKey(bool $include_extra = true): string
{
return 'key-of<' . $this->param_name . '>';
}
public function getId(bool $exact = true, bool $nested = false): string
{
if (!$exact) {
return 'key-of<' . $this->param_name . '>';
}
return 'key-of<' . $this->as->getId($exact) . '>';
}
/**
* @param array<lowercase-string, string> $aliased_classes
*/
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
): string {
return 'key-of<' . $this->param_name . '>';
}
/**
* @param array<lowercase-string, string> $aliased_classes
*/
public function toPhpString(
?string $namespace,
array $aliased_classes,
?string $this_class,
int $analysis_php_version_id
): ?string {
return null;
}
public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
{
return false;
}
public function replaceTemplateTypesWithArgTypes(
TemplateResult $template_result,
?Codebase $codebase
): void {
TemplateInferredTypeReplacer::replace(
$this->as,
$template_result,
$codebase
);
}
}