Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Analyser/FileAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ public function analyseFile(
}
if ($node instanceof InTraitNode) {
$traitNode = $node->getOriginalNode();
$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.


$traitFileName = $node->getTraitReflection()->getFileName();
if ($traitFileName !== null) {
Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,18 @@ public function testBug13980(): void
$this->assertNoErrors($errors);
}

public function testBug13945(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-13945.php');
$this->assertNoErrors($errors);
}

public function testBug13945Two(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-13945-2.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return list<Error>
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/data/bug-13945-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Bug13945Two;

trait Foo {
public function baz(): void {
$this->myProperty = "a"; // @phpstan-ignore property.notFound
}
}

trait Baz {
}

class HelloWorld
{
use Baz;
use Foo;
}
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/data/bug-13945.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Bug13945;

trait Foo {
public function baz(): void {
$this->myProperty = "a"; // @phpstan-ignore property.notFound
}
}

trait Baz {
}

class HelloWorld
{
use Foo;
use Baz;
Comment on lines +16 to +17
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

}
Loading