Skip to content

Commit

Permalink
PhpFunctionFromParserNodeReflection becomes ParametersAcceptorWithPhp…
Browse files Browse the repository at this point in the history
…Docs
  • Loading branch information
ondrejmirtes committed Sep 26, 2024
1 parent 0e2587f commit 1bea5c7
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions src/Reflection/Php/PhpFunctionFromParserNodeReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVarianceMap;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\TypehintHelper;
Expand All @@ -26,7 +27,7 @@
/**
* @api
*/
class PhpFunctionFromParserNodeReflection implements FunctionReflection
class PhpFunctionFromParserNodeReflection implements FunctionReflection, ParametersAcceptorWithPhpDocs
{

/** @var Function_|ClassMethod */
Expand Down Expand Up @@ -101,12 +102,12 @@ public function getVariants(): array
if ($this->variants === null) {
$this->variants = [
new FunctionVariantWithPhpDocs(
$this->templateTypeMap,
null,
$this->getTemplateTypeMap(),
$this->getResolvedTemplateTypeMap(),
$this->getParameters(),
$this->isVariadic(),
$this->getReturnType(),
$this->phpDocReturnType ?? new MixedType(),
$this->getPhpDocReturnType(),
$this->realReturnType,
),
];
Expand All @@ -120,10 +121,20 @@ public function getNamedArgumentsVariants(): ?array
return null;
}

public function getTemplateTypeMap(): TemplateTypeMap
{
return $this->templateTypeMap;
}

public function getResolvedTemplateTypeMap(): TemplateTypeMap
{
return TemplateTypeMap::createEmpty();
}

/**
* @return ParameterReflectionWithPhpDocs[]
* @return array<int, ParameterReflectionWithPhpDocs>
*/
private function getParameters(): array
public function getParameters(): array
{
$parameters = [];
$isOptional = true;
Expand Down Expand Up @@ -169,7 +180,7 @@ private function getParameters(): array
return array_reverse($parameters);
}

private function isVariadic(): bool
public function isVariadic(): bool
{
foreach ($this->functionLike->getParams() as $parameter) {
if ($parameter->variadic) {
Expand All @@ -180,11 +191,26 @@ private function isVariadic(): bool
return false;
}

protected function getReturnType(): Type
public function getReturnType(): Type
{
return TypehintHelper::decideType($this->realReturnType, $this->phpDocReturnType);
}

public function getPhpDocReturnType(): Type
{
return $this->phpDocReturnType ?? new MixedType();
}

public function getNativeReturnType(): Type
{
return $this->realReturnType;
}

public function getCallSiteVarianceMap(): TemplateTypeVarianceMap
{
return TemplateTypeVarianceMap::createEmpty();
}

public function getDeprecatedDescription(): ?string
{
if ($this->isDeprecated) {
Expand Down

0 comments on commit 1bea5c7

Please sign in to comment.