Skip to content

Commit

Permalink
Fix: Use more appropriate message when detecting protected method in …
Browse files Browse the repository at this point in the history
…final anonymous class
  • Loading branch information
localheinz committed Jan 6, 2025
1 parent 8a20466 commit ff8ad44
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Methods/PrivateInFinalClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ public function processNode(
}
}

/** @var Reflection\ClassReflection $classReflection */
$classReflection = $scope->getClassReflection();

if ($classReflection->isAnonymous()) {
$message = \sprintf(
'Method %s() in anonymous class is protected, but since the containing class is final, it can be private.',
$node->name->name,
);

return [
Rules\RuleErrorBuilder::message($message)
->identifier(ErrorIdentifier::privateInFinalClass()->toString())
->build(),
];
}

$message = \sprintf(
'Method %s::%s() is protected, but since the containing class is final, it can be private.',
$containingClass->getName(),
Expand Down

0 comments on commit ff8ad44

Please sign in to comment.