Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 17, 2021
1 parent 89acb0d commit 716fe52
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"nette/utils": "^3.1.3",
"nikic/php-parser": "4.12.0",
"ondram/ci-detector": "^3.4.0",
"ondrejmirtes/better-reflection": "4.3.63",
"ondrejmirtes/better-reflection": "4.3.64",
"phpstan/php-8-stubs": "^0.1.22",
"phpstan/phpdoc-parser": "^0.5.5",
"react/child-process": "^0.6.1",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/Reflection/ClassConstantReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Reflection;

use PHPStan\Php\PhpVersion;
use PHPStan\TrinaryLogic;
use PHPStan\Type\ConstantTypeHelper;
use PHPStan\Type\Type;
Expand All @@ -15,6 +16,8 @@ class ClassConstantReflection implements ConstantReflection

private ?Type $phpDocType;

private PhpVersion $phpVersion;

private ?string $deprecatedDescription;

private bool $isDeprecated;
Expand All @@ -27,6 +30,7 @@ public function __construct(
ClassReflection $declaringClass,
\ReflectionClassConstant $reflection,
?Type $phpDocType,
PhpVersion $phpVersion,
?string $deprecatedDescription,
bool $isDeprecated,
bool $isInternal
Expand All @@ -35,6 +39,7 @@ public function __construct(
$this->declaringClass = $declaringClass;
$this->reflection = $reflection;
$this->phpDocType = $phpDocType;
$this->phpVersion = $phpVersion;
$this->deprecatedDescription = $deprecatedDescription;
$this->isDeprecated = $isDeprecated;
$this->isInternal = $isInternal;
Expand Down Expand Up @@ -107,7 +112,11 @@ public function isFinal(): bool
return $this->reflection->isFinal();
}

return false;
if (!$this->phpVersion->isInterfaceConstantImplicitlyFinal()) {
return false;
}

return $this->declaringClass->isInterface();
}

public function isDeprecated(): TrinaryLogic
Expand Down
1 change: 1 addition & 0 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ public function getConstant(string $name): ConstantReflection
$declaringClass,
$reflectionConstant,
$phpDocType,
$this->phpVersion,
$deprecatedDescription,
$isDeprecated,
$isInternal
Expand Down
13 changes: 1 addition & 12 deletions src/Rules/Constants/OverridingConstantRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Php\PhpVersion;
use PHPStan\Reflection\ClassConstantReflection;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ConstantReflection;
Expand All @@ -19,16 +18,12 @@
class OverridingConstantRule implements Rule
{

private PhpVersion $phpVersion;

private bool $checkPhpDocMethodSignatures;

public function __construct(
PhpVersion $phpVersion,
bool $checkPhpDocMethodSignatures
)
{
$this->phpVersion = $phpVersion;
$this->checkPhpDocMethodSignatures = $checkPhpDocMethodSignatures;
}

Expand Down Expand Up @@ -69,13 +64,7 @@ private function processSingleConstant(ClassReflection $classReflection, string
}

$errors = [];
if (
$prototype->isFinal()
|| (
$this->phpVersion->isInterfaceConstantImplicitlyFinal()
&& $prototype->getDeclaringClass()->isInterface()
)
) {
if ($prototype->isFinal()) {
$errors[] = RuleErrorBuilder::message(sprintf(
'Constant %s::%s overrides final constant %s::%s.',
$classReflection->getDisplayName(),
Expand Down
3 changes: 1 addition & 2 deletions tests/PHPStan/Rules/Constants/OverridingConstantRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PHPStan\Rules\Constants;

use PHPStan\Php\PhpVersion;
use PHPStan\Testing\RuleTestCase;

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

protected function getRule(): \PHPStan\Rules\Rule
{
return new OverridingConstantRule(new PhpVersion(PHP_VERSION_ID), true);
return new OverridingConstantRule(true);
}

public function testRule(): void
Expand Down

0 comments on commit 716fe52

Please sign in to comment.