-
Notifications
You must be signed in to change notification settings - Fork 660
/
TKeyOfClassConstant.php
122 lines (107 loc) · 3 KB
/
TKeyOfClassConstant.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace Psalm\Type\Atomic;
class TKeyOfClassConstant extends Scalar
{
/** @var string */
public $fq_classlike_name;
/** @var string */
public $const_name;
/**
* @param string $fq_classlike_name
* @param string $const_name
*/
public function __construct($fq_classlike_name, $const_name)
{
$this->fq_classlike_name = $fq_classlike_name;
$this->const_name = $const_name;
}
/**
* @return string
*/
public function getKey()
{
return 'key-of<' . $this->fq_classlike_name . '::' . $this->const_name . '>';
}
/**
* @return string
*/
public function __toString()
{
return 'key-of<' . $this->fq_classlike_name . '::' . $this->const_name . '>';
}
/**
* @return string
*/
public function getId()
{
return $this->getKey();
}
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param string|null $this_class
* @param int $php_major_version
* @param int $php_minor_version
*
* @return string|null
*/
public function toPhpString(
$namespace,
array $aliased_classes,
$this_class,
$php_major_version,
$php_minor_version
) {
return null;
}
public function canBeFullyExpressedInPhp()
{
return false;
}
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param string|null $this_class
* @param bool $use_phpdoc_format
*
* @return string
*/
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
) {
if ($this->fq_classlike_name === 'static') {
return 'key-of<static::' . $this->const_name . '>';
}
if ($this->fq_classlike_name === $this_class) {
return 'key-of<self::' . $this->const_name . '>';
}
if ($namespace && stripos($this->fq_classlike_name, $namespace . '\\') === 0) {
return 'key-of<' . preg_replace(
'/^' . preg_quote($namespace . '\\') . '/i',
'',
$this->fq_classlike_name
) . '::' . $this->const_name . '>';
}
if (!$namespace && stripos($this->fq_classlike_name, '\\') === false) {
return 'key-of<' . $this->fq_classlike_name . '::' . $this->const_name . '>';
}
if (isset($aliased_classes[strtolower($this->fq_classlike_name)])) {
return 'key-of<'
. $aliased_classes[strtolower($this->fq_classlike_name)]
. '::'
. $this->const_name
. '>';
}
return 'key-of<\\' . $this->fq_classlike_name . '::' . $this->const_name . '>';
}
/**
* @return string
*/
public function getAssertionString()
{
return 'mixed';
}
}