|
3 | 3 | namespace PHPStan\Reflection;
|
4 | 4 |
|
5 | 5 | use PhpParser\Node\Expr;
|
6 |
| -use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClassConstant; |
7 |
| -use PHPStan\TrinaryLogic; |
8 | 6 | use PHPStan\Type\Type;
|
9 |
| -use PHPStan\Type\TypehintHelper; |
10 | 7 |
|
11 |
| -/** |
12 |
| - * @api |
13 |
| - */ |
14 |
| -final class ClassConstantReflection implements ConstantReflection |
| 8 | +/** @api */ |
| 9 | +interface ClassConstantReflection extends ClassMemberReflection, ConstantReflection |
15 | 10 | {
|
16 | 11 |
|
17 |
| - private ?Type $valueType = null; |
| 12 | + public function getValueExpr(): Expr; |
18 | 13 |
|
19 |
| - public function __construct( |
20 |
| - private InitializerExprTypeResolver $initializerExprTypeResolver, |
21 |
| - private ClassReflection $declaringClass, |
22 |
| - private ReflectionClassConstant $reflection, |
23 |
| - private ?Type $nativeType, |
24 |
| - private ?Type $phpDocType, |
25 |
| - private ?string $deprecatedDescription, |
26 |
| - private bool $isDeprecated, |
27 |
| - private bool $isInternal, |
28 |
| - ) |
29 |
| - { |
30 |
| - } |
| 14 | + public function isFinal(): bool; |
31 | 15 |
|
32 |
| - public function getName(): string |
33 |
| - { |
34 |
| - return $this->reflection->getName(); |
35 |
| - } |
| 16 | + public function hasPhpDocType(): bool; |
36 | 17 |
|
37 |
| - public function getFileName(): ?string |
38 |
| - { |
39 |
| - return $this->declaringClass->getFileName(); |
40 |
| - } |
| 18 | + public function getPhpDocType(): ?Type; |
41 | 19 |
|
42 |
| - public function getValueExpr(): Expr |
43 |
| - { |
44 |
| - return $this->reflection->getValueExpression(); |
45 |
| - } |
| 20 | + public function hasNativeType(): bool; |
46 | 21 |
|
47 |
| - public function hasPhpDocType(): bool |
48 |
| - { |
49 |
| - return $this->phpDocType !== null; |
50 |
| - } |
51 |
| - |
52 |
| - public function getPhpDocType(): ?Type |
53 |
| - { |
54 |
| - return $this->phpDocType; |
55 |
| - } |
56 |
| - |
57 |
| - public function hasNativeType(): bool |
58 |
| - { |
59 |
| - return $this->nativeType !== null; |
60 |
| - } |
61 |
| - |
62 |
| - public function getNativeType(): ?Type |
63 |
| - { |
64 |
| - return $this->nativeType; |
65 |
| - } |
66 |
| - |
67 |
| - public function getValueType(): Type |
68 |
| - { |
69 |
| - if ($this->valueType === null) { |
70 |
| - if ($this->phpDocType !== null) { |
71 |
| - if ($this->nativeType !== null) { |
72 |
| - return $this->valueType = TypehintHelper::decideType( |
73 |
| - $this->nativeType, |
74 |
| - $this->phpDocType, |
75 |
| - ); |
76 |
| - } |
77 |
| - |
78 |
| - return $this->phpDocType; |
79 |
| - } elseif ($this->nativeType !== null) { |
80 |
| - return $this->nativeType; |
81 |
| - } |
82 |
| - |
83 |
| - $this->valueType = $this->initializerExprTypeResolver->getType($this->getValueExpr(), InitializerExprContext::fromClassReflection($this->declaringClass)); |
84 |
| - } |
85 |
| - |
86 |
| - return $this->valueType; |
87 |
| - } |
88 |
| - |
89 |
| - public function getDeclaringClass(): ClassReflection |
90 |
| - { |
91 |
| - return $this->declaringClass; |
92 |
| - } |
93 |
| - |
94 |
| - public function isStatic(): bool |
95 |
| - { |
96 |
| - return true; |
97 |
| - } |
98 |
| - |
99 |
| - public function isPrivate(): bool |
100 |
| - { |
101 |
| - return $this->reflection->isPrivate(); |
102 |
| - } |
103 |
| - |
104 |
| - public function isPublic(): bool |
105 |
| - { |
106 |
| - return $this->reflection->isPublic(); |
107 |
| - } |
108 |
| - |
109 |
| - public function isFinal(): bool |
110 |
| - { |
111 |
| - return $this->reflection->isFinal(); |
112 |
| - } |
113 |
| - |
114 |
| - public function isDeprecated(): TrinaryLogic |
115 |
| - { |
116 |
| - return TrinaryLogic::createFromBoolean($this->isDeprecated); |
117 |
| - } |
118 |
| - |
119 |
| - public function getDeprecatedDescription(): ?string |
120 |
| - { |
121 |
| - if ($this->isDeprecated) { |
122 |
| - return $this->deprecatedDescription; |
123 |
| - } |
124 |
| - |
125 |
| - return null; |
126 |
| - } |
127 |
| - |
128 |
| - public function isInternal(): TrinaryLogic |
129 |
| - { |
130 |
| - return TrinaryLogic::createFromBoolean($this->isInternal); |
131 |
| - } |
132 |
| - |
133 |
| - public function getDocComment(): ?string |
134 |
| - { |
135 |
| - $docComment = $this->reflection->getDocComment(); |
136 |
| - if ($docComment === false) { |
137 |
| - return null; |
138 |
| - } |
139 |
| - |
140 |
| - return $docComment; |
141 |
| - } |
| 22 | + public function getNativeType(): ?Type; |
142 | 23 |
|
143 | 24 | }
|
0 commit comments