Skip to content

Interface_exists check around class/trait not detected #3460

@acrobat

Description

@acrobat

Bug report

KnpLabs/php-github-api when have a interface_exists check around a trait to provide support for httplug v1 and v2.

Since updating phpstan/phpstan (0.12.24 => 0.12.28) we get an error. It seems that phpstan always ends up in the else statement instead of the correct part based on the actual check. We are running phpstan with v2 of httplug so it should use the trait from the if part.

Now we get this error

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Github/HttpClient/Plugin/HistoryTrait.php (in context of class Github\HttpClient\Plugin\History)
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------
  28     Parameter #2 $exception (Http\Client\Exception) of method Github\HttpClient\Plugin\History::addFailure() is not compatible with parameter #2 $exception
         (Psr\Http\Client\ClientExceptionInterface) of method Http\Client\Common\Plugin\Journal::addFailure().
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------

Code snippet that reproduces the problem

https://github.com/KnpLabs/php-github-api/blob/d557dc4b43b44aeeef14c8f531809cd6ebcbbbc1/lib/Github/HttpClient/Plugin/HistoryTrait.php#L9-L32

I think this is a correct reproducer: https://phpstan.org/r/d47b3549-6e08-4948-a540-27bb868ad61f

Expected output

No error reported.

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