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
6 changes: 6 additions & 0 deletions src/Rules/Traits/ConflictingTraitConstantsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

// Even though isInClass() is true, we still need to check isInTrait() because
// both can be true simultaneously when analyzing trait code.
if ($scope->isInTrait()) {
return [];
}

$classReflection = $scope->getClassReflection();
$traitConstants = [];
foreach ($classReflection->getTraits(true) as $trait) {
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Traits/data/conflicting-trait-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,21 @@ class Bar10

final public const PUBLIC_FINAL_CONSTANT = 1;
}

trait Foo1
{
protected const ARR1 = [
self::KEY => 'int',
];
}

class Bar11
{
use Foo1;

protected const KEY = 'k1';

protected const ARR = self::ARR1 + [
'a.b' => 'int',
];
}
Loading