From ff8ad44eb6d6e87c90cd9b61ed8518e82470f197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 09:54:04 +0100 Subject: [PATCH] Fix: Use more appropriate message when detecting protected method in final anonymous class --- src/Methods/PrivateInFinalClassRule.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 4c6ce4d7..ec1f5062 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -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(),