DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
75 stars 9 forks source link

Wrong string-class template detection #546

Closed Morgy93 closed 2 months ago

Morgy93 commented 2 months ago

Hello,

I have a method like:

    /**
     * Returns view model instance for given FQN
     *
     * @template T
     * @param string-class<T> $viewModelClass Fully qualified class name (FQN)
     * @param AbstractBlock|null $block Only required if view model is used within a template cached in ESI (ttl="n" in layout XML)
     * @return T
     * @throw InvalidViewModelClass if class not found or not a view model
     */
    public function require(string $viewModelClass, AbstractBlock $block = null): ArgumentInterface

Using it throws an PHP0406 | Argument type mismatch error:

$class->require(\Some\Class:class)

Argument '1' passed to require() is expected to be of type Class\With\Require\string-class, string given

Any idea what's wrong here?

jakubmisek commented 2 months ago

Thank you for the question.

I think the standard name is class-string (not string-class) https://phpstan.org/writing-php-code/phpdoc-types#class-string

We can support both if it's used by some other code sniffer.

Morgy93 commented 2 months ago

Interesting, that code is provided by a third party.

But it seems that it should be class-string indeed.

I'll open a PR on that code. If there is any reason, they need it like this, I'll update this issue.

Thank you 🙌

jakubmisek commented 2 months ago

Thank you @Morgy93 - please let us know if there will be anything we can do.