diff --git a/src/Expression/ForClasses/IsFinal.php b/src/Expression/ForClasses/IsFinal.php index 2290a751..0723f188 100644 --- a/src/Expression/ForClasses/IsFinal.php +++ b/src/Expression/ForClasses/IsFinal.php @@ -20,7 +20,7 @@ public function describe(ClassDescription $theClass, string $because): Descripti public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void { - if ($theClass->isAbstract() || $theClass->isInterface() || $theClass->isFinal()) { + if ($theClass->isAbstract() || $theClass->isInterface() || $theClass->isFinal() || $theClass->isTrait()) { return; } diff --git a/tests/Unit/Expressions/ForClasses/IsFinalTest.php b/tests/Unit/Expressions/ForClasses/IsFinalTest.php index a9e52feb..c783740e 100644 --- a/tests/Unit/Expressions/ForClasses/IsFinalTest.php +++ b/tests/Unit/Expressions/ForClasses/IsFinalTest.php @@ -97,4 +97,25 @@ public function test_interfaces_can_not_be_final_and_should_be_ignored(): void $isFinal->evaluate($classDescription, $violations, $because); self::assertEquals(0, $violations->count()); } + + public function test_traits_can_not_be_final_and_should_be_ignored(): void + { + $class = 'myClass'; + + $isFinal = new IsFinal(); + $classDescription = new ClassDescription( + FullyQualifiedClassName::fromString('HappyIsland'), + [], + [], + null, + false, + false, + false, + true + ); + $because = 'we want to add this rule for our software'; + $violations = new Violations(); + $isFinal->evaluate($classDescription, $violations, $because); + self::assertEquals(0, $violations->count()); + } }