Skip to content

Commit 5a162f1

Browse files
fix isFinal, isAbstract, isReadonly behaviour
1 parent 414ec7a commit 5a162f1

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

src/Expression/ForClasses/IsAbstract.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public function describe(ClassDescription $theClass, string $because): Descripti
2020

2121
public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void
2222
{
23-
if ($theClass->isAbstract() || $theClass->isInterface() || $theClass->isTrait() || $theClass->isEnum()
24-
|| $theClass->isFinal()) {
23+
if ($theClass->isAbstract()) {
2524
return;
2625
}
2726

src/Expression/ForClasses/IsFinal.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public function describe(ClassDescription $theClass, string $because): Descripti
2020

2121
public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void
2222
{
23-
if ($theClass->isAbstract() || $theClass->isInterface() || $theClass->isFinal() || $theClass->isTrait()
24-
|| $theClass->isEnum()) {
23+
if ($theClass->isFinal()) {
2524
return;
2625
}
2726

src/Expression/ForClasses/IsReadonly.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function describe(ClassDescription $theClass, string $because): Descripti
2020

2121
public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void
2222
{
23-
if ($theClass->isReadonly() || $theClass->isInterface() || $theClass->isTrait() || $theClass->isEnum()) {
23+
if ($theClass->isReadonly()) {
2424
return;
2525
}
2626

tests/E2E/PHPUnit/CheckClassWithMultipleExpressionsTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Arkitect\Tests\E2E\PHPUnit;
56

67
use Arkitect\ClassSet;
8+
use Arkitect\Expression\ForClasses\HaveNameMatching;
9+
use Arkitect\Expression\ForClasses\IsAbstract;
710
use Arkitect\Expression\ForClasses\IsNotAbstract;
811
use Arkitect\Expression\ForClasses\IsNotEnum;
912
use Arkitect\Expression\ForClasses\IsNotFinal;
@@ -33,4 +36,16 @@ public function test_it_can_check_multiple_expressions(): void
3336

3437
ArchRuleTestCase::assertArchRule($rule, $set);
3538
}
39+
40+
public function test_is_final(): void
41+
{
42+
$set = ClassSet::fromDir(__DIR__.'/../_fixtures/is_final');
43+
44+
$rule = Rule::allClasses()
45+
->that(new IsAbstract())
46+
->should(new HaveNameMatching('Abstract*'))
47+
->because('we want to prefix abstract classes');
48+
49+
ArchRuleTestCase::assertArchRule($rule, $set);
50+
}
3651
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App;
6+
7+
final class MyClass
8+
{
9+
}

0 commit comments

Comments
 (0)