Skip to content

[PropertyInfo] Extract no type param annotation with PhpStanExtractor #59923

Closed
@thomasdubuffet

Description

@thomasdubuffet

Symfony version(s) affected

7.2

Description

An Undefined property error is issued when a @param annotation has a name without typing (PhpStanExtractor context).

Undefined property: PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode::$type
src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php:219

How to reproduce

class InvalidDummy
{
    /**
     * @param $data
     */
    public function setData($data)
    {
    }
}

Variable $extractor is an instance of Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor

$extractor->getType(InvalidDummy::class, 'data');

Possible Solution

Update method getType in PhpStanExtractor to add a check on TypelessParamTagValueNode

if ($tagDocNode->value instanceof InvalidTagValueNode || $tagDocNode->value instanceof TypelessParamTagValueNode) {
    continue;
}

if ($tagDocNode->value instanceof ParamTagValueNode && null === $prefix && $tagDocNode->value->parameterName !== '$'.$property) {
    continue;
}

try {
    $types[] = $this->stringTypeResolver->resolve((string) $tagDocNode->value->type, $typeContext);
} catch (UnsupportedException) {
}

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions