Skip to content

Return tag with constant wildcard list parsed into InvalidTag instead of Return_ #261

Open
@andrew-demb

Description

@andrew-demb

Documentation for this syntax: https://psalm.dev/docs/annotating_code/typing_in_psalm/#specifying-stringint-options-aka-enums

Example code:

class Some
{
    public const STATUS_FOO = 'foo';
    public const STATUS_BAR = 'bar';

    /**
     * @return self::STATUS_*
     */
    public function dummy(): string
    {
        return self::STATUS_FOO;
    }
}

Test:

<?php

declare(strict_types=1);

use phpDocumentor\Reflection\DocBlock\Tags\Return_;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Psr16Cache;
use TheCodingMachine\GraphQLite\Reflection\CachedDocBlockFactory;

final class GithubTest extends TestCase
{
    public function testGithub(): void
    {
        $cachedDocBlockFactory = new CachedDocBlockFactory(new Psr16Cache(new ArrayAdapter()));

        $refMethod = new \ReflectionMethod($this, 'dummy');
        $docBlockObj = $cachedDocBlockFactory->getDocBlock($refMethod);

        $returnTag = $docBlockObj->getTagsByName('return')[0] ?? null;

        $this->assertInstanceOf(Return_::class, $returnTag);
    }

    public const STATUS_FOO = 'foo';
    public const STATUS_BAR = 'bar';

    /**
     * @return self::STATUS_*
     */
    public function dummy(): string
    {
        return self::STATUS_FOO;
    }
}

Current output:

Failed asserting that phpDocumentor\Reflection\DocBlock\Tags\InvalidTag Object (...) is an instance of class "phpDocumentor\Reflection\DocBlock\Tags\Return_".
 /.../tests/GithubTest.php:24

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions