From 0ec48cca15a178388f03d2766b55b6c23a35705a Mon Sep 17 00:00:00 2001 From: Luke Kuzmish <42181698+cosmastech@users.noreply.github.com> Date: Sun, 17 Nov 2024 08:23:27 -0500 Subject: [PATCH] do not throw error is method is marked as #[Before] --- src/Methods/PrivateInFinalClassRule.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index b552ecbb..42e2dbf3 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -19,8 +19,13 @@ use PHPStan\Rules; use PHPStan\ShouldNotHappenException; + final class PrivateInFinalClassRule implements Rules\Rule { + private static $attributesThatIndicateProtectedIsOk = [ + \PHPUnit\Framework\Attributes\Before::class + ]; + public function getNodeType(): string { return Node\Stmt\ClassMethod::class; @@ -53,6 +58,15 @@ public function processNode( return []; } + // Check attributes + foreach($node->attrGroups as $attrGroup) { + foreach($attrGroup->attrs as $attr) { + if (in_array($attr->name->toString(), self::$attributesThatIndicateProtectedIsOk)) { + return []; + } + } + } + $methodName = $node->name->toString(); $parentClass = $containingClass->getNativeReflection()->getParentClass();