psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Docbloc: callable() is not a valid method

Open gmazzap opened this issue 10 months ago • 1 comments

Psalm, rightfully, does not complain when encountering an actual method named callable.

But it does complain if the method is in a @method docblock.

Note: this is specific to "callable". Method named as other types such as "string", "int" or "bool" do not cause any issue.

See https://psalm.dev/r/c91fa34de9

gmazzap avatar Apr 15 '24 08:04 gmazzap

I found these snippets:

https://psalm.dev/r/c91fa34de9
<?php

/**
 * @method static Type string()
 * @method static Type int()
 * @method static Type float()
 *
 * @method Type callable()
 */
class Foo
{
    public function __call(string $name, array $arguments): string
    {
        if ($name === 'callable') {
            return 'Callable is a valid method name';
        }
        
        throw new \Error('Invalid method');
    }
}

class Bar
{
    public function callable(): void
    {
    }
    
    public function string(): void
    {
    }
    
    public function int(): void
    {
    }
    
    public function float(): void
    {
    }
}
Psalm output (using commit 08afc45):

ERROR: InvalidDocblock - 10:7 - callable() is not a valid method in docblock for Foo

psalm-github-bot[bot] avatar Apr 15 '24 08:04 psalm-github-bot[bot]