Skip to content

Conversation

@takaram
Copy link
Contributor

@takaram takaram commented Jan 22, 2026

$linesToIgnore data was not correctly gathered when:

  • more than one traits are defined in a same file
  • those traits are used in a same class

Closes phpstan/phpstan#13945

Comment on lines +16 to +17
use Foo;
use Baz;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in phpstan/phpstan#13945 its reported that the errors emitted depend on the order of this use-statements.

I think it would be good than, to additional test this with use in different order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test case

$linesToIgnore[$scope->getFileDescription()] = $this->getLinesToIgnoreFromTokens([$traitNode]);
$fileDescription = $scope->getFileDescription();
$linesToIgnore[$fileDescription] ??= [];
$linesToIgnore[$fileDescription] += $this->getLinesToIgnoreFromTokens([$traitNode]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain what's happening here? $scope->getFileDescription() should be unique per trait usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of $scope->getFileDescription() contains:

  • File path where the trait is defined
  • Name of the class which uses the trait

It does not contain trait name, so is not necessarily unique when a file has two or more traits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

phpstan-ignore not working when using multiple trait

3 participants