🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

if.alwaysTrue when found in traits isn't reported correctly through context of a user class #14932

Description

@Numynum

Bug report

As seen in the example, deadCode.unreachable is found twice, in the context of the using classes.
But if.alwaysTrue is only found in the trait itself.
When generating a baseline, it seems to just "randomly" pick a class to write the ignored error for, leading to inconsistent results in our development vs CI pipeline.

Analysis result:

 3/3 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec

 ------ ------------------------------
  Line   FooTrait.php
 ------ ------------------------------
  15     If condition is always true.
         🪪  if.alwaysTrue
 ------ ------------------------------

 ------ -------------------------------------------------------
  Line   FooTrait.php (in context of class Bar)
 ------ -------------------------------------------------------
  19     Unreachable statement - code above always terminates.
         🪪  deadCode.unreachable
 ------ -------------------------------------------------------

 ------ -------------------------------------------------------
  Line   FooTrait.php (in context of class Foo)
 ------ -------------------------------------------------------
  19     Unreachable statement - code above always terminates.
         🪪  deadCode.unreachable
 ------ -------------------------------------------------------

Code snippet that reproduces the problem

https://phpstan.org/r/73efdd9c-0534-4553-9447-2f94e94bbefd

Expected output

if.alwaysTrue in a trait should always be reported in context of a class instead

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

love the tool, it's helped find and prevent so many issues ❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions