16
16
use PHPStan \ShouldNotHappenException ;
17
17
use PHPStan \TrinaryLogic ;
18
18
use PHPStan \Type \Generic \TemplateTypeMap ;
19
+ use PHPStan \Type \Generic \TemplateTypeVarianceMap ;
19
20
use PHPStan \Type \MixedType ;
20
21
use PHPStan \Type \Type ;
21
22
use PHPStan \Type \TypehintHelper ;
26
27
/**
27
28
* @api
28
29
*/
29
- class PhpFunctionFromParserNodeReflection implements FunctionReflection
30
+ class PhpFunctionFromParserNodeReflection implements FunctionReflection, ParametersAcceptorWithPhpDocs
30
31
{
31
32
32
33
/** @var Function_|ClassMethod */
@@ -101,12 +102,12 @@ public function getVariants(): array
101
102
if ($ this ->variants === null ) {
102
103
$ this ->variants = [
103
104
new FunctionVariantWithPhpDocs (
104
- $ this ->templateTypeMap ,
105
- null ,
105
+ $ this ->getTemplateTypeMap () ,
106
+ $ this -> getResolvedTemplateTypeMap () ,
106
107
$ this ->getParameters (),
107
108
$ this ->isVariadic (),
108
109
$ this ->getReturnType (),
109
- $ this ->phpDocReturnType ?? new MixedType (),
110
+ $ this ->getPhpDocReturnType (),
110
111
$ this ->realReturnType ,
111
112
),
112
113
];
@@ -120,10 +121,20 @@ public function getNamedArgumentsVariants(): ?array
120
121
return null ;
121
122
}
122
123
124
+ public function getTemplateTypeMap (): TemplateTypeMap
125
+ {
126
+ return $ this ->templateTypeMap ;
127
+ }
128
+
129
+ public function getResolvedTemplateTypeMap (): TemplateTypeMap
130
+ {
131
+ return TemplateTypeMap::createEmpty ();
132
+ }
133
+
123
134
/**
124
- * @return ParameterReflectionWithPhpDocs[]
135
+ * @return array<int, ParameterReflectionWithPhpDocs>
125
136
*/
126
- private function getParameters (): array
137
+ public function getParameters (): array
127
138
{
128
139
$ parameters = [];
129
140
$ isOptional = true ;
@@ -169,7 +180,7 @@ private function getParameters(): array
169
180
return array_reverse ($ parameters );
170
181
}
171
182
172
- private function isVariadic (): bool
183
+ public function isVariadic (): bool
173
184
{
174
185
foreach ($ this ->functionLike ->getParams () as $ parameter ) {
175
186
if ($ parameter ->variadic ) {
@@ -180,11 +191,26 @@ private function isVariadic(): bool
180
191
return false ;
181
192
}
182
193
183
- protected function getReturnType (): Type
194
+ public function getReturnType (): Type
184
195
{
185
196
return TypehintHelper::decideType ($ this ->realReturnType , $ this ->phpDocReturnType );
186
197
}
187
198
199
+ public function getPhpDocReturnType (): Type
200
+ {
201
+ return $ this ->phpDocReturnType ?? new MixedType ();
202
+ }
203
+
204
+ public function getNativeReturnType (): Type
205
+ {
206
+ return $ this ->realReturnType ;
207
+ }
208
+
209
+ public function getCallSiteVarianceMap (): TemplateTypeVarianceMap
210
+ {
211
+ return TemplateTypeVarianceMap::createEmpty ();
212
+ }
213
+
188
214
public function getDeprecatedDescription (): ?string
189
215
{
190
216
if ($ this ->isDeprecated ) {
0 commit comments