Skip to content
Merged
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
5 changes: 1 addition & 4 deletions src/Rules/Traits/ConflictingTraitConstantsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ public function processNode(Node $node, Scope $scope): array
$classConstantValueType = $this->initializerExprTypeResolver->getType($const->value, InitializerExprContext::fromClassReflection($classReflection));
$traitConstantValueType = $this->initializerExprTypeResolver->getType(
$immediateTraitConstant->getValueExpression(),
InitializerExprContext::fromClass(
$immediateTraitConstant->getDeclaringClass()->getName(),
$immediateTraitConstant->getDeclaringClass()->getFileName() !== false ? $immediateTraitConstant->getDeclaringClass()->getFileName() : null,
),
InitializerExprContext::fromClassReflection($classReflection),
);
if ($classConstantValueType->equals($traitConstantValueType)) {
continue;
Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Traits/ConflictingTraitConstantsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,22 @@ public function testNativeTypes(): void
]);
}

#[RequiresPhp('>= 8.2')]
public function testBug11088(): void
{
$this->analyse([__DIR__ . '/data/bug-11088.php'], []);
}

#[RequiresPhp('>= 8.3')]
public function testBug13119(): void
{
$this->analyse([__DIR__ . '/data/bug-13119.php'], []);
}

#[RequiresPhp('>= 8.2')]
public function testBug11351(): void
{
$this->analyse([__DIR__ . '/data/bug-11351.php'], []);
}

}
23 changes: 23 additions & 0 deletions tests/PHPStan/Rules/Traits/data/bug-11088.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php // lint >= 8.2

declare(strict_types=1);

namespace Bug11088;

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

class HelloWorld
{
use Foo;

protected const KEY = 'k1';

protected const ARR = self::ARR1 + [
'a.b' => 'int',
];
}
45 changes: 45 additions & 0 deletions tests/PHPStan/Rules/Traits/data/bug-11351.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php // lint >= 8.2

declare(strict_types = 1);

namespace Bug11351;

trait TA
{
protected const A = [
self::CA => 'CA',
];
}

class A
{
use TA;
public const CA = 'abc';
}

trait TB
{
protected const B = [
'key' => self::CB,
];
}

class B
{
use TB;
public const CB = 'value';
}

trait TC
{
protected const C = [
self::CC1 => self::CC2,
];
}

class C
{
use TC;
public const CC1 = 'key';
public const CC2 = 'value';
}
Loading