Skip to content

Commit

Permalink
fix: (#360)
Browse files Browse the repository at this point in the history
- abstract classes can not be final
- interfaces can not be final
  • Loading branch information
sebastianstucke87 authored Feb 17, 2023
1 parent 1bc83bb commit 6b8f553
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/IsFinal.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function describe(ClassDescription $theClass, string $because): Descripti

public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void
{
if ($theClass->isFinal()) {
if ($theClass->isAbstract() || $theClass->isInterface() || $theClass->isFinal()) {
return;
}

Expand Down
40 changes: 40 additions & 0 deletions tests/Unit/Expressions/ForClasses/IsFinalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,44 @@ public function test_it_should_return_true_if_is_final(): void
$isFinal->evaluate($classDescription, $violations, $because);
self::assertEquals(0, $violations->count());
}

public function test_abstract_classes_can_not_be_final_and_should_be_ignored(): void
{
$class = 'myClass';

$isFinal = new IsFinal();
$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland'),
[],
[],
null,
false,
true,
false
);
$because = 'we want to add this rule for our software';
$violations = new Violations();
$isFinal->evaluate($classDescription, $violations, $because);
self::assertEquals(0, $violations->count());
}

public function test_interfaces_can_not_be_final_and_should_be_ignored(): void
{
$class = 'myClass';

$isFinal = new IsFinal();
$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland'),
[],
[],
null,
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());
}
}

0 comments on commit 6b8f553

Please sign in to comment.