Skip to content

Stub files not overriding @method annotations #6422

@ndench

Description

@ndench

Bug report

I'm trying to write a stub file for FakerPHP/Faker, specifically for the randomElement() method which is defined by an @method annotation. It appears that my stub file is being completely ignored and I cannot figure out why.

I've enabled xdebug and stepped through the analyse command to ensure that the stub is being read. This is backed up by phpstan displaying errors if I make the stub file invalid.

Code snippet that reproduces the problem

Here is a snippet which shows the error: https://phpstan.org/r/263ad808-dab7-4003-b7be-b816c02c1401

Here is the stub file I've written:

// Generator.stub
<?php

namespace Faker;

class Generator
{
    /**
     * @template T
     * @param array<array-key, T> $array
     *
     * @return T
     */
    public function randomElement(array $array): mixed;
}

To test further, I changed the stub file in a way that should make any call to ->randomElement() throw an error. But no errors were reported at all.

// Generator.stub
<?php

namespace Faker;

class Generator
{
    /**
     * @param string $array
     * @return string
     */
    public function randomElement(string $array): string;
}

Expected output

I expected the stub file to inform PHPStan of the return type for randomElement.

Did PHPStan help you today? Did it make you happy in any way?

I've been using PHPStan for almost 4 years, and I'm very impressed with the speed improvements over that time ❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions