Skip to content

Commit 1bea5c7

Browse files
committedSep 26, 2024
PhpFunctionFromParserNodeReflection becomes ParametersAcceptorWithPhpDocs
1 parent 0e2587f commit 1bea5c7

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed
 

‎src/Reflection/Php/PhpFunctionFromParserNodeReflection.php

+34-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPStan\ShouldNotHappenException;
1717
use PHPStan\TrinaryLogic;
1818
use PHPStan\Type\Generic\TemplateTypeMap;
19+
use PHPStan\Type\Generic\TemplateTypeVarianceMap;
1920
use PHPStan\Type\MixedType;
2021
use PHPStan\Type\Type;
2122
use PHPStan\Type\TypehintHelper;
@@ -26,7 +27,7 @@
2627
/**
2728
* @api
2829
*/
29-
class PhpFunctionFromParserNodeReflection implements FunctionReflection
30+
class PhpFunctionFromParserNodeReflection implements FunctionReflection, ParametersAcceptorWithPhpDocs
3031
{
3132

3233
/** @var Function_|ClassMethod */
@@ -101,12 +102,12 @@ public function getVariants(): array
101102
if ($this->variants === null) {
102103
$this->variants = [
103104
new FunctionVariantWithPhpDocs(
104-
$this->templateTypeMap,
105-
null,
105+
$this->getTemplateTypeMap(),
106+
$this->getResolvedTemplateTypeMap(),
106107
$this->getParameters(),
107108
$this->isVariadic(),
108109
$this->getReturnType(),
109-
$this->phpDocReturnType ?? new MixedType(),
110+
$this->getPhpDocReturnType(),
110111
$this->realReturnType,
111112
),
112113
];
@@ -120,10 +121,20 @@ public function getNamedArgumentsVariants(): ?array
120121
return null;
121122
}
122123

124+
public function getTemplateTypeMap(): TemplateTypeMap
125+
{
126+
return $this->templateTypeMap;
127+
}
128+
129+
public function getResolvedTemplateTypeMap(): TemplateTypeMap
130+
{
131+
return TemplateTypeMap::createEmpty();
132+
}
133+
123134
/**
124-
* @return ParameterReflectionWithPhpDocs[]
135+
* @return array<int, ParameterReflectionWithPhpDocs>
125136
*/
126-
private function getParameters(): array
137+
public function getParameters(): array
127138
{
128139
$parameters = [];
129140
$isOptional = true;
@@ -169,7 +180,7 @@ private function getParameters(): array
169180
return array_reverse($parameters);
170181
}
171182

172-
private function isVariadic(): bool
183+
public function isVariadic(): bool
173184
{
174185
foreach ($this->functionLike->getParams() as $parameter) {
175186
if ($parameter->variadic) {
@@ -180,11 +191,26 @@ private function isVariadic(): bool
180191
return false;
181192
}
182193

183-
protected function getReturnType(): Type
194+
public function getReturnType(): Type
184195
{
185196
return TypehintHelper::decideType($this->realReturnType, $this->phpDocReturnType);
186197
}
187198

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+
188214
public function getDeprecatedDescription(): ?string
189215
{
190216
if ($this->isDeprecated) {

0 commit comments

Comments
 (0)