-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathOrx.php
More file actions
43 lines (36 loc) · 1.2 KB
/
Orx.php
File metadata and controls
43 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace Arkitect\Expression\Boolean;
use Arkitect\Analyzer\ClassDescription;
use Arkitect\Expression\Description;
use Arkitect\Expression\Expression;
use Arkitect\Rules\Violation;
use Arkitect\Rules\ViolationMessage;
use Arkitect\Rules\Violations;
final class Orx implements Expression
{
/** @var Expression[] */
private $expressions;
public function __construct(array $expressions)
{
$this->expressions = $expressions;
}
public function describe(ClassDescription $theClass, string $because): Description
{
return new Description('at least one expression must be true', $because);
}
public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void
{
foreach ($this->expressions as $expression) {
$newViolations = new Violations();
$expression->evaluate($theClass, $newViolations, $because);
if (0 === $newViolations->count()) {
return;
}
}
$violations->add(Violation::create(
$theClass->getFQCN(),
ViolationMessage::selfExplanatory($this->describe($theClass, $because))
));
}
}