Skip to content

Commit

Permalink
Fully qualify the name of the #[\Override] attribute in error messages
Browse files Browse the repository at this point in the history
This makes the attribute definition from the error message copy and paste safe
for namespaced classes.

As PHP attributes do not need to be backed by a class, using the non-qualified
`#[Override]` variant without a matching `use Override;` appears to look
correct at a quick glance, but will not actually do anything useful.
  • Loading branch information
TimWolla committed Nov 15, 2023
1 parent 231ed3e commit 5fb82dc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Rules/Methods/OverridingMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function processNode(Node $node, Scope $scope): array
if ($this->phpVersion->supportsOverrideAttribute() && $this->hasOverrideAttribute($node->getOriginalNode())) {
return [
RuleErrorBuilder::message(sprintf(
'Method %s::%s() has #[Override] attribute but does not override any method.',
'Method %s::%s() has #[\Override] attribute but does not override any method.',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
))
Expand All @@ -110,7 +110,7 @@ public function processNode(Node $node, Scope $scope): array
&& !$this->hasOverrideAttribute($node->getOriginalNode())
) {
$messages[] = RuleErrorBuilder::message(sprintf(
'Method %s::%s() overrides method %s::%s() but is missing the #[Override] attribute.',
'Method %s::%s() overrides method %s::%s() but is missing the #[\Override] attribute.',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototype->getDeclaringClass()->getDisplayName($this->genericPrototypeMessage),
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ public function testOverrideAttribute(): void
$this->phpVersionId = PHP_VERSION_ID;
$this->analyse([__DIR__ . '/data/override-attribute.php'], [
[
'Method OverrideAttribute\Bar::test2() has #[Override] attribute but does not override any method.',
'Method OverrideAttribute\Bar::test2() has #[\Override] attribute but does not override any method.',
24,
],
]);
Expand All @@ -761,7 +761,7 @@ public function dataCheckMissingOverrideAttribute(): iterable
yield [false, 80300, []];
yield [true, 80300, [
[
'Method CheckMissingOverrideAttr\Bar::doFoo() overrides method CheckMissingOverrideAttr\Foo::doFoo() but is missing the #[Override] attribute.',
'Method CheckMissingOverrideAttr\Bar::doFoo() overrides method CheckMissingOverrideAttr\Foo::doFoo() but is missing the #[\Override] attribute.',
18,
],
]];
Expand Down

0 comments on commit 5fb82dc

Please sign in to comment.