Skip to content

Commit 99e2ffa

Browse files
committed
Remove the PHP version constraint from the #[\Override] attribute rules.
1 parent c8a1ae1 commit 99e2ffa

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/Rules/Methods/OverridingMethodRule.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker $scope): array
8787
}
8888
}
8989

90-
if ($this->phpVersion->supportsOverrideAttribute() && $this->hasOverrideAttribute($node->getOriginalNode())) {
90+
if ($this->hasOverrideAttribute($node->getOriginalNode())) {
9191
return [
9292
RuleErrorBuilder::message(sprintf(
9393
'Method %s::%s() has #[\Override] attribute but does not override any method.',
@@ -111,8 +111,7 @@ public function processNode(Node $node, Scope&NodeCallbackInvoker $scope): array
111111

112112
$messages = [];
113113
if (
114-
$this->phpVersion->supportsOverrideAttribute()
115-
&& $this->checkMissingOverrideMethodAttribute
114+
$this->checkMissingOverrideMethodAttribute
116115
&& !$scope->isInTrait()
117116
&& !$this->hasOverrideAttribute($node->getOriginalNode())
118117
) {

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,6 @@ public function testTraits(): void
726726
$this->analyse([__DIR__ . '/data/overriding-trait-methods.php'], $errors);
727727
}
728728

729-
#[RequiresPhp('>= 8.3')]
730729
public function testOverrideAttribute(): void
731730
{
732731
$this->phpVersionId = PHP_VERSION_ID;
@@ -745,7 +744,16 @@ public function testOverrideAttribute(): void
745744
public static function dataCheckMissingOverrideAttribute(): iterable
746745
{
747746
yield [false, 80000, []];
748-
yield [true, 80000, []];
747+
yield [true, 80000, [
748+
[
749+
'Method CheckMissingOverrideAttr\Bar::doFoo() overrides method CheckMissingOverrideAttr\Foo::doFoo() but is missing the #[\Override] attribute.',
750+
18,
751+
],
752+
[
753+
'Method CheckMissingOverrideAttr\ChildOfParentWithAbstractConstructor::__construct() overrides method CheckMissingOverrideAttr\ParentWithAbstractConstructor::__construct() but is missing the #[\Override] attribute.',
754+
49,
755+
],
756+
]];
749757
yield [false, 80300, []];
750758
yield [true, 80300, [
751759
[
@@ -785,7 +793,6 @@ public function testBug10153(): void
785793
$this->analyse([__DIR__ . '/data/bug-10153.php'], $errors);
786794
}
787795

788-
#[RequiresPhp('>= 8.3')]
789796
public function testBug12471(): void
790797
{
791798
$this->checkMissingOverrideMethodAttribute = true;
@@ -812,15 +819,13 @@ public function testSimpleXmlElementChildClass(): void
812819
$this->analyse([__DIR__ . '/data/simple-xml-element-child.php'], []);
813820
}
814821

815-
#[RequiresPhp('>= 8.3')]
816822
public function testFixOverride(): void
817823
{
818824
$this->phpVersionId = PHP_VERSION_ID;
819825
$this->checkMissingOverrideMethodAttribute = true;
820826
$this->fix(__DIR__ . '/data/fix-override-attribute.php', __DIR__ . '/data/fix-override-attribute.php.fixed');
821827
}
822828

823-
#[RequiresPhp('>= 8.3')]
824829
public function testFixWithTabs(): void
825830
{
826831
$this->phpVersionId = PHP_VERSION_ID;

0 commit comments

Comments
 (0)