-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added isFinal and isNotFinal rule (#241)
- Loading branch information
1 parent
efc2ea8
commit ee33724
Showing
13 changed files
with
252 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Arkitect\Expression\ForClasses; | ||
|
||
use Arkitect\Analyzer\ClassDescription; | ||
use Arkitect\Expression\Description; | ||
use Arkitect\Expression\Expression; | ||
use Arkitect\Expression\PositiveDescription; | ||
use Arkitect\Rules\Violation; | ||
use Arkitect\Rules\Violations; | ||
|
||
class IsFinal implements Expression | ||
{ | ||
public function describe(ClassDescription $theClass): Description | ||
{ | ||
return new PositiveDescription("{$theClass->getName()} should be final"); | ||
} | ||
|
||
public function evaluate(ClassDescription $theClass, Violations $violations): void | ||
{ | ||
if ($theClass->isFinal()) { | ||
return; | ||
} | ||
|
||
$violation = Violation::create( | ||
$theClass->getFQCN(), | ||
$this->describe($theClass)->toString() | ||
); | ||
|
||
$violations->add($violation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Arkitect\Expression\ForClasses; | ||
|
||
use Arkitect\Analyzer\ClassDescription; | ||
use Arkitect\Expression\Description; | ||
use Arkitect\Expression\Expression; | ||
use Arkitect\Expression\PositiveDescription; | ||
use Arkitect\Rules\Violation; | ||
use Arkitect\Rules\Violations; | ||
|
||
class IsNotFinal implements Expression | ||
{ | ||
public function describe(ClassDescription $theClass): Description | ||
{ | ||
return new PositiveDescription("{$theClass->getName()} should not be final"); | ||
} | ||
|
||
public function evaluate(ClassDescription $theClass, Violations $violations): void | ||
{ | ||
if (!$theClass->isFinal()) { | ||
return; | ||
} | ||
|
||
$violation = Violation::create( | ||
$theClass->getFQCN(), | ||
$this->describe($theClass)->toString() | ||
); | ||
|
||
$violations->add($violation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Arkitect\Tests\Unit\Expressions\ForClasses; | ||
|
||
use Arkitect\Analyzer\ClassDescription; | ||
use Arkitect\Analyzer\FullyQualifiedClassName; | ||
use Arkitect\Expression\ForClasses\IsFinal; | ||
use Arkitect\Rules\Violations; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class IsFinalTest extends TestCase | ||
{ | ||
public function test_it_should_return_violation_error(): void | ||
{ | ||
$isFinal = new IsFinal(); | ||
$classDescription = new ClassDescription( | ||
FullyQualifiedClassName::fromString('HappyIsland'), | ||
[], | ||
[], | ||
null, | ||
false | ||
); | ||
|
||
$violationError = $isFinal->describe($classDescription)->toString(); | ||
|
||
$violations = new Violations(); | ||
$isFinal->evaluate($classDescription, $violations); | ||
self::assertNotEquals(0, $violations->count()); | ||
|
||
$this->assertEquals('HappyIsland should be final', $violationError); | ||
} | ||
|
||
public function test_it_should_return_true_if_is_final(): void | ||
{ | ||
$class = 'myClass'; | ||
|
||
$isFinal = new IsFinal(); | ||
$classDescription = new ClassDescription( | ||
FullyQualifiedClassName::fromString('HappyIsland'), | ||
[], | ||
[], | ||
null, | ||
true | ||
); | ||
|
||
$violations = new Violations(); | ||
$isFinal->evaluate($classDescription, $violations); | ||
self::assertEquals(0, $violations->count()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Arkitect\Tests\Unit\Expressions\ForClasses; | ||
|
||
use Arkitect\Analyzer\ClassDescription; | ||
use Arkitect\Analyzer\FullyQualifiedClassName; | ||
use Arkitect\Expression\ForClasses\IsNotFinal; | ||
use Arkitect\Rules\Violations; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class IsNotFinalTest extends TestCase | ||
{ | ||
public function test_it_should_return_violation_error(): void | ||
{ | ||
$isFinal = new IsNotFinal(); | ||
$classDescription = new ClassDescription( | ||
FullyQualifiedClassName::fromString('HappyIsland'), | ||
[], | ||
[], | ||
null, | ||
true | ||
); | ||
|
||
$violationError = $isFinal->describe($classDescription)->toString(); | ||
|
||
$violations = new Violations(); | ||
$isFinal->evaluate($classDescription, $violations); | ||
self::assertNotEquals(0, $violations->count()); | ||
|
||
$this->assertEquals('HappyIsland should not be final', $violationError); | ||
} | ||
|
||
public function test_it_should_return_true_if_is_final(): void | ||
{ | ||
$isFinal = new IsNotFinal(); | ||
$classDescription = new ClassDescription( | ||
FullyQualifiedClassName::fromString('HappyIsland'), | ||
[], | ||
[], | ||
null, | ||
false | ||
); | ||
|
||
$violations = new Violations(); | ||
$isFinal->evaluate($classDescription, $violations); | ||
self::assertEquals(0, $violations->count()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.