Skip to content

if I assert using assertInstanceOf it must not report an error afterwards  #21

@gmponos

Description

@gmponos

Hello

Inside a unit test I had a code like this

        $collector = $client->getProfile()->getCollector('request');

because $client->getProfile() can return false|Profile phpstan was reporting the following issue:

 20     Cannot call method getCollector() on                                                                
         false|Symfony\Component\HttpKernel\Profiler\Profile.
 ------ ---------------------------------------------------------------------------------------------------- 

I changed my code to something like this:

        $profiler = $client->getProfile();
        $this->assertInstanceOf(Profile::class, $profiler);

        $collector = $profiler->getCollector('request');

And the error was still reported. So finally I had to add this /** @var Profile $profiler */ inline docblock in order for the error not to be reported and trick PHPstan.

I believe that since you do an assertInstanceOf there is no need to display an error and having to trick PHPstan by adding inline docblock. Is this possible to be fixed?

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