2
2
3
3
namespace PHPStan \Reflection \Php ;
4
4
5
- use PHPStan \BetterReflection \Reflection \Adapter \ReflectionIntersectionType ;
6
- use PHPStan \BetterReflection \Reflection \Adapter \ReflectionNamedType ;
7
5
use PHPStan \BetterReflection \Reflection \Adapter \ReflectionProperty ;
8
- use PHPStan \BetterReflection \Reflection \Adapter \ReflectionUnionType ;
9
6
use PHPStan \Reflection \AttributeReflection ;
10
7
use PHPStan \Reflection \ClassReflection ;
11
8
use PHPStan \Reflection \ExtendedMethodReflection ;
24
21
final class PhpPropertyReflection implements ExtendedPropertyReflection
25
22
{
26
23
27
- private ?Type $ finalNativeType = null ;
28
-
29
24
private ?Type $ readableType = null ;
30
25
31
26
private ?Type $ writableType = null ;
@@ -36,7 +31,7 @@ final class PhpPropertyReflection implements ExtendedPropertyReflection
36
31
public function __construct (
37
32
private ClassReflection $ declaringClass ,
38
33
private ?ClassReflection $ declaringTrait ,
39
- private ReflectionUnionType | ReflectionNamedType | ReflectionIntersectionType | null $ nativeType ,
34
+ private Type $ nativeType ,
40
35
private ?Type $ readablePhpDocType ,
41
36
private ?Type $ writablePhpDocType ,
42
37
private ReflectionProperty $ reflection ,
@@ -109,10 +104,9 @@ public function isReadOnlyByPhpDoc(): bool
109
104
110
105
public function getReadableType (): Type
111
106
{
112
- return $ this ->readableType ??= TypehintHelper::decideTypeFromReflection (
107
+ return $ this ->readableType ??= TypehintHelper::decideType (
113
108
$ this ->nativeType ,
114
109
$ this ->readablePhpDocType ,
115
- $ this ->declaringClass ,
116
110
);
117
111
}
118
112
@@ -131,10 +125,9 @@ public function getWritableType(): Type
131
125
}
132
126
133
127
if ($ this ->writablePhpDocType === null || $ this ->writablePhpDocType instanceof NeverType) {
134
- return $ this ->writableType = TypehintHelper::decideTypeFromReflection (
128
+ return $ this ->writableType = TypehintHelper::decideType (
135
129
$ this ->nativeType ,
136
130
$ this ->readablePhpDocType ,
137
- $ this ->declaringClass ,
138
131
);
139
132
}
140
133
@@ -145,10 +138,9 @@ public function getWritableType(): Type
145
138
return $ this ->writableType = $ this ->writablePhpDocType ;
146
139
}
147
140
148
- return $ this ->writableType = TypehintHelper::decideTypeFromReflection (
141
+ return $ this ->writableType = TypehintHelper::decideType (
149
142
$ this ->nativeType ,
150
143
$ this ->writablePhpDocType ,
151
- $ this ->declaringClass ,
152
144
);
153
145
}
154
146
@@ -194,15 +186,12 @@ public function getPhpDocType(): Type
194
186
195
187
public function hasNativeType (): bool
196
188
{
197
- return $ this ->nativeType !== null ;
189
+ return ! $ this ->nativeType instanceof MixedType || $ this -> nativeType -> isExplicitMixed () ;
198
190
}
199
191
200
192
public function getNativeType (): Type
201
193
{
202
- return $ this ->finalNativeType ??= TypehintHelper::decideTypeFromReflection (
203
- $ this ->nativeType ,
204
- selfClass: $ this ->declaringClass ,
205
- );
194
+ return $ this ->nativeType ;
206
195
}
207
196
208
197
public function isReadable (): bool
0 commit comments