22
33namespace PHPStan \Reflection \Php ;
44
5- use PHPStan \BetterReflection \Reflection \Adapter \ReflectionIntersectionType ;
6- use PHPStan \BetterReflection \Reflection \Adapter \ReflectionNamedType ;
75use PHPStan \BetterReflection \Reflection \Adapter \ReflectionProperty ;
8- use PHPStan \BetterReflection \Reflection \Adapter \ReflectionUnionType ;
96use PHPStan \Reflection \AttributeReflection ;
107use PHPStan \Reflection \ClassReflection ;
118use PHPStan \Reflection \ExtendedMethodReflection ;
2421final class PhpPropertyReflection implements ExtendedPropertyReflection
2522{
2623
27- private ?Type $ finalNativeType = null ;
28-
2924 private ?Type $ readableType = null ;
3025
3126 private ?Type $ writableType = null ;
@@ -36,7 +31,7 @@ final class PhpPropertyReflection implements ExtendedPropertyReflection
3631 public function __construct (
3732 private ClassReflection $ declaringClass ,
3833 private ?ClassReflection $ declaringTrait ,
39- private ReflectionUnionType | ReflectionNamedType | ReflectionIntersectionType | null $ nativeType ,
34+ private Type $ nativeType ,
4035 private ?Type $ readablePhpDocType ,
4136 private ?Type $ writablePhpDocType ,
4237 private ReflectionProperty $ reflection ,
@@ -109,10 +104,9 @@ public function isReadOnlyByPhpDoc(): bool
109104
110105 public function getReadableType (): Type
111106 {
112- return $ this ->readableType ??= TypehintHelper::decideTypeFromReflection (
107+ return $ this ->readableType ??= TypehintHelper::decideType (
113108 $ this ->nativeType ,
114109 $ this ->readablePhpDocType ,
115- $ this ->declaringClass ,
116110 );
117111 }
118112
@@ -131,10 +125,9 @@ public function getWritableType(): Type
131125 }
132126
133127 if ($ this ->writablePhpDocType === null || $ this ->writablePhpDocType instanceof NeverType) {
134- return $ this ->writableType = TypehintHelper::decideTypeFromReflection (
128+ return $ this ->writableType = TypehintHelper::decideType (
135129 $ this ->nativeType ,
136130 $ this ->readablePhpDocType ,
137- $ this ->declaringClass ,
138131 );
139132 }
140133
@@ -145,10 +138,9 @@ public function getWritableType(): Type
145138 return $ this ->writableType = $ this ->writablePhpDocType ;
146139 }
147140
148- return $ this ->writableType = TypehintHelper::decideTypeFromReflection (
141+ return $ this ->writableType = TypehintHelper::decideType (
149142 $ this ->nativeType ,
150143 $ this ->writablePhpDocType ,
151- $ this ->declaringClass ,
152144 );
153145 }
154146
@@ -194,15 +186,12 @@ public function getPhpDocType(): Type
194186
195187 public function hasNativeType (): bool
196188 {
197- return $ this ->nativeType !== null ;
189+ return ! $ this ->nativeType instanceof MixedType || $ this -> nativeType -> isExplicitMixed () ;
198190 }
199191
200192 public function getNativeType (): Type
201193 {
202- return $ this ->finalNativeType ??= TypehintHelper::decideTypeFromReflection (
203- $ this ->nativeType ,
204- selfClass: $ this ->declaringClass ,
205- );
194+ return $ this ->nativeType ;
206195 }
207196
208197 public function isReadable (): bool
0 commit comments