28
28
use PHPStan \Reflection \TrivialParametersAcceptor ;
29
29
use PHPStan \Reflection \Type \CalledOnTypeUnresolvedMethodPrototypeReflection ;
30
30
use PHPStan \Reflection \Type \CalledOnTypeUnresolvedPropertyPrototypeReflection ;
31
- use PHPStan \Reflection \Type \UnionTypePropertyReflection ;
31
+ use PHPStan \Reflection \Type \UnionTypeUnresolvedPropertyPrototypeReflection ;
32
32
use PHPStan \Reflection \Type \UnresolvedMethodPrototypeReflection ;
33
33
use PHPStan \Reflection \Type \UnresolvedPropertyPrototypeReflection ;
34
34
use PHPStan \ShouldNotHappenException ;
@@ -155,29 +155,6 @@ public function hasProperty(string $propertyName): TrinaryLogic
155
155
156
156
public function getProperty (string $ propertyName , ClassMemberAccessAnswerer $ scope ): PropertyReflection
157
157
{
158
- $ classReflection = $ this ->getClassReflection ();
159
- if ($ classReflection !== null ) {
160
- if ($ classReflection ->isEnum ()) {
161
- if (
162
- $ propertyName === 'name '
163
- || ($ propertyName === 'value ' && $ classReflection ->isBackedEnum ())
164
- ) {
165
- $ properties = [];
166
- foreach ($ this ->getEnumCases () as $ enumCase ) {
167
- $ properties [] = $ enumCase ->getProperty ($ propertyName , $ scope );
168
- }
169
-
170
- if (count ($ properties ) > 0 ) {
171
- if (count ($ properties ) === 1 ) {
172
- return $ properties [0 ];
173
- }
174
-
175
- return new UnionTypePropertyReflection ($ properties );
176
- }
177
- }
178
- }
179
- }
180
-
181
158
return $ this ->getUnresolvedPropertyPrototype ($ propertyName , $ scope )->getTransformedProperty ();
182
159
}
183
160
@@ -199,6 +176,26 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember
199
176
throw new ClassNotFoundException ($ this ->className );
200
177
}
201
178
179
+ if ($ nakedClassReflection ->isEnum ()) {
180
+ if (
181
+ $ propertyName === 'name '
182
+ || ($ propertyName === 'value ' && $ nakedClassReflection ->isBackedEnum ())
183
+ ) {
184
+ $ properties = [];
185
+ foreach ($ this ->getEnumCases () as $ enumCase ) {
186
+ $ properties [] = $ enumCase ->getUnresolvedPropertyPrototype ($ propertyName , $ scope );
187
+ }
188
+
189
+ if (count ($ properties ) > 0 ) {
190
+ if (count ($ properties ) === 1 ) {
191
+ return $ properties [0 ];
192
+ }
193
+
194
+ return new UnionTypeUnresolvedPropertyPrototypeReflection ($ propertyName , $ properties );
195
+ }
196
+ }
197
+ }
198
+
202
199
if (!$ nakedClassReflection ->hasNativeProperty ($ propertyName )) {
203
200
$ nakedClassReflection = $ this ->getClassReflection ();
204
201
}
0 commit comments