Skip to content

Commit 716fe52

Browse files
committed
Fix
1 parent 89acb0d commit 716fe52

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"nette/utils": "^3.1.3",
2424
"nikic/php-parser": "4.12.0",
2525
"ondram/ci-detector": "^3.4.0",
26-
"ondrejmirtes/better-reflection": "4.3.63",
26+
"ondrejmirtes/better-reflection": "4.3.64",
2727
"phpstan/php-8-stubs": "^0.1.22",
2828
"phpstan/phpdoc-parser": "^0.5.5",
2929
"react/child-process": "^0.6.1",

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Reflection/ClassConstantReflection.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Reflection;
44

5+
use PHPStan\Php\PhpVersion;
56
use PHPStan\TrinaryLogic;
67
use PHPStan\Type\ConstantTypeHelper;
78
use PHPStan\Type\Type;
@@ -15,6 +16,8 @@ class ClassConstantReflection implements ConstantReflection
1516

1617
private ?Type $phpDocType;
1718

19+
private PhpVersion $phpVersion;
20+
1821
private ?string $deprecatedDescription;
1922

2023
private bool $isDeprecated;
@@ -27,6 +30,7 @@ public function __construct(
2730
ClassReflection $declaringClass,
2831
\ReflectionClassConstant $reflection,
2932
?Type $phpDocType,
33+
PhpVersion $phpVersion,
3034
?string $deprecatedDescription,
3135
bool $isDeprecated,
3236
bool $isInternal
@@ -35,6 +39,7 @@ public function __construct(
3539
$this->declaringClass = $declaringClass;
3640
$this->reflection = $reflection;
3741
$this->phpDocType = $phpDocType;
42+
$this->phpVersion = $phpVersion;
3843
$this->deprecatedDescription = $deprecatedDescription;
3944
$this->isDeprecated = $isDeprecated;
4045
$this->isInternal = $isInternal;
@@ -107,7 +112,11 @@ public function isFinal(): bool
107112
return $this->reflection->isFinal();
108113
}
109114

110-
return false;
115+
if (!$this->phpVersion->isInterfaceConstantImplicitlyFinal()) {
116+
return false;
117+
}
118+
119+
return $this->declaringClass->isInterface();
111120
}
112121

113122
public function isDeprecated(): TrinaryLogic

src/Reflection/ClassReflection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ public function getConstant(string $name): ConstantReflection
821821
$declaringClass,
822822
$reflectionConstant,
823823
$phpDocType,
824+
$this->phpVersion,
824825
$deprecatedDescription,
825826
$isDeprecated,
826827
$isInternal

src/Rules/Constants/OverridingConstantRule.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
7-
use PHPStan\Php\PhpVersion;
87
use PHPStan\Reflection\ClassConstantReflection;
98
use PHPStan\Reflection\ClassReflection;
109
use PHPStan\Reflection\ConstantReflection;
@@ -19,16 +18,12 @@
1918
class OverridingConstantRule implements Rule
2019
{
2120

22-
private PhpVersion $phpVersion;
23-
2421
private bool $checkPhpDocMethodSignatures;
2522

2623
public function __construct(
27-
PhpVersion $phpVersion,
2824
bool $checkPhpDocMethodSignatures
2925
)
3026
{
31-
$this->phpVersion = $phpVersion;
3227
$this->checkPhpDocMethodSignatures = $checkPhpDocMethodSignatures;
3328
}
3429

@@ -69,13 +64,7 @@ private function processSingleConstant(ClassReflection $classReflection, string
6964
}
7065

7166
$errors = [];
72-
if (
73-
$prototype->isFinal()
74-
|| (
75-
$this->phpVersion->isInterfaceConstantImplicitlyFinal()
76-
&& $prototype->getDeclaringClass()->isInterface()
77-
)
78-
) {
67+
if ($prototype->isFinal()) {
7968
$errors[] = RuleErrorBuilder::message(sprintf(
8069
'Constant %s::%s overrides final constant %s::%s.',
8170
$classReflection->getDisplayName(),

tests/PHPStan/Rules/Constants/OverridingConstantRuleTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Rules\Constants;
44

5-
use PHPStan\Php\PhpVersion;
65
use PHPStan\Testing\RuleTestCase;
76

87
/** @extends RuleTestCase<OverridingConstantRule> */
@@ -11,7 +10,7 @@ class OverridingConstantRuleTest extends RuleTestCase
1110

1211
protected function getRule(): \PHPStan\Rules\Rule
1312
{
14-
return new OverridingConstantRule(new PhpVersion(PHP_VERSION_ID), true);
13+
return new OverridingConstantRule(true);
1514
}
1615

1716
public function testRule(): void

0 commit comments

Comments
 (0)