25
25
use PHPStan \Reflection \Deprecation \DeprecationProvider ;
26
26
use PHPStan \Reflection \ExtendedFunctionVariant ;
27
27
use PHPStan \Reflection \ExtendedMethodReflection ;
28
- use PHPStan \Reflection \ExtendedPropertyReflection ;
29
28
use PHPStan \Reflection \InitializerExprContext ;
30
29
use PHPStan \Reflection \MethodReflection ;
31
30
use PHPStan \Reflection \MethodsClassReflectionExtension ;
@@ -69,7 +68,7 @@ final class PhpClassReflectionExtension
69
68
implements PropertiesClassReflectionExtension, MethodsClassReflectionExtension
70
69
{
71
70
72
- /** @var ExtendedPropertyReflection [][] */
71
+ /** @var PhpPropertyReflection [][] */
73
72
private array $ propertiesIncludingAnnotations = [];
74
73
75
74
/** @var PhpPropertyReflection[][] */
@@ -159,7 +158,7 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
159
158
return $ classReflection ->getNativeReflection ()->hasProperty ($ propertyName );
160
159
}
161
160
162
- public function getProperty (ClassReflection $ classReflection , string $ propertyName ): ExtendedPropertyReflection
161
+ public function getProperty (ClassReflection $ classReflection , string $ propertyName ): PhpPropertyReflection
163
162
{
164
163
if (!isset ($ this ->propertiesIncludingAnnotations [$ classReflection ->getCacheKey ()][$ propertyName ])) {
165
164
$ this ->propertiesIncludingAnnotations [$ classReflection ->getCacheKey ()][$ propertyName ] = $ this ->createProperty ($ classReflection , $ propertyName , true );
@@ -171,7 +170,6 @@ public function getProperty(ClassReflection $classReflection, string $propertyNa
171
170
public function getNativeProperty (ClassReflection $ classReflection , string $ propertyName ): PhpPropertyReflection
172
171
{
173
172
if (!isset ($ this ->nativeProperties [$ classReflection ->getCacheKey ()][$ propertyName ])) {
174
- /** @var PhpPropertyReflection $property */
175
173
$ property = $ this ->createProperty ($ classReflection , $ propertyName , false );
176
174
$ this ->nativeProperties [$ classReflection ->getCacheKey ()][$ propertyName ] = $ property ;
177
175
}
@@ -183,7 +181,7 @@ private function createProperty(
183
181
ClassReflection $ classReflection ,
184
182
string $ propertyName ,
185
183
bool $ includingAnnotations ,
186
- ): ExtendedPropertyReflection
184
+ ): PhpPropertyReflection
187
185
{
188
186
$ propertyReflection = $ classReflection ->getNativeReflection ()->getProperty ($ propertyName );
189
187
$ propertyName = $ propertyReflection ->getName ();
@@ -230,31 +228,6 @@ private function createProperty(
230
228
$ isFinal = $ classReflection ->isFinal () || $ propertyReflection ->isFinal ();
231
229
$ isAllowedPrivateMutation = false ;
232
230
233
- if (
234
- $ includingAnnotations
235
- && !$ declaringClassReflection ->isEnum ()
236
- && $ this ->annotationsPropertiesClassReflectionExtension ->hasProperty ($ classReflection , $ propertyName )
237
- ) {
238
- $ hierarchyDistances = $ classReflection ->getClassHierarchyDistances ();
239
- $ annotationProperty = $ this ->annotationsPropertiesClassReflectionExtension ->getProperty ($ classReflection , $ propertyName );
240
- if (!isset ($ hierarchyDistances [$ annotationProperty ->getDeclaringClass ()->getName ()])) {
241
- throw new ShouldNotHappenException ();
242
- }
243
-
244
- $ distanceDeclaringClass = $ propertyReflection ->getDeclaringClass ()->getName ();
245
- $ propertyTrait = $ this ->findPropertyTrait ($ propertyReflection );
246
- if ($ propertyTrait !== null ) {
247
- $ distanceDeclaringClass = $ propertyTrait ;
248
- }
249
- if (!isset ($ hierarchyDistances [$ distanceDeclaringClass ])) {
250
- throw new ShouldNotHappenException ();
251
- }
252
-
253
- if ($ hierarchyDistances [$ annotationProperty ->getDeclaringClass ()->getName ()] <= $ hierarchyDistances [$ distanceDeclaringClass ]) {
254
- return $ annotationProperty ;
255
- }
256
- }
257
-
258
231
$ docComment = $ propertyReflection ->getDocComment () !== false
259
232
? $ propertyReflection ->getDocComment ()
260
233
: null ;
@@ -423,6 +396,46 @@ private function createProperty(
423
396
}
424
397
}
425
398
399
+ if (
400
+ $ includingAnnotations
401
+ && !$ declaringClassReflection ->isEnum ()
402
+ && $ this ->annotationsPropertiesClassReflectionExtension ->hasProperty ($ classReflection , $ propertyName )
403
+ ) {
404
+ $ hierarchyDistances = $ classReflection ->getClassHierarchyDistances ();
405
+ $ annotationProperty = $ this ->annotationsPropertiesClassReflectionExtension ->getProperty ($ classReflection , $ propertyName );
406
+ if (!isset ($ hierarchyDistances [$ annotationProperty ->getDeclaringClass ()->getName ()])) {
407
+ throw new ShouldNotHappenException ();
408
+ }
409
+
410
+ $ distanceDeclaringClass = $ propertyReflection ->getDeclaringClass ()->getName ();
411
+ $ propertyTrait = $ this ->findPropertyTrait ($ propertyReflection );
412
+ if ($ propertyTrait !== null ) {
413
+ $ distanceDeclaringClass = $ propertyTrait ;
414
+ }
415
+ if (!isset ($ hierarchyDistances [$ distanceDeclaringClass ])) {
416
+ throw new ShouldNotHappenException ();
417
+ }
418
+
419
+ if ($ hierarchyDistances [$ annotationProperty ->getDeclaringClass ()->getName ()] <= $ hierarchyDistances [$ distanceDeclaringClass ]) {
420
+ return new PhpPropertyReflection (
421
+ $ annotationProperty ->getDeclaringClass (),
422
+ $ declaringTrait ,
423
+ $ nativeType ,
424
+ $ annotationProperty ->getPhpDocType (),
425
+ $ propertyReflection ,
426
+ $ getHook ,
427
+ $ setHook ,
428
+ $ deprecatedDescription ,
429
+ $ isDeprecated ,
430
+ $ isInternal ,
431
+ $ isReadOnlyByPhpDoc ,
432
+ $ isAllowedPrivateMutation ,
433
+ $ this ->attributeReflectionFactory ->fromNativeReflection ($ propertyReflection ->getAttributes (), InitializerExprContext::fromClass ($ declaringClassReflection ->getName (), $ declaringClassReflection ->getFileName ())),
434
+ $ isFinal ,
435
+ );
436
+ }
437
+ }
438
+
426
439
return new PhpPropertyReflection (
427
440
$ declaringClassReflection ,
428
441
$ declaringTrait ,
0 commit comments