-
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathNegateDecorator.php
More file actions
57 lines (47 loc) · 1.47 KB
/
NegateDecorator.php
File metadata and controls
57 lines (47 loc) · 1.47 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace Arkitect\Expression;
use Arkitect\Analyzer\ClassDescription;
use Arkitect\Rules\Violation;
use Arkitect\Rules\ViolationMessage;
use Arkitect\Rules\Violations;
class NegateDecorator implements Expression
{
/** @var Expression */
private $expression;
public function __construct(Expression $expression)
{
$this->expression = $expression;
}
public function describe(ClassDescription $theClass, string $because): Description
{
$description = $this->expression->describe($theClass, $because)->toString();
$description = str_replace(
['should not'],
['should'],
$description,
$count
);
if (0 === $count) {
$description = str_replace(
['should'],
['should not'],
$description,
$count
);
}
return new Description($description, '');
}
public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void
{
$this->expression->evaluate($theClass, $currentViolations = new Violations(), $because);
if (0 === $currentViolations->count()) {
$violations->add(
Violation::create(
$theClass->getFQCN(),
ViolationMessage::selfExplanatory($this->describe($theClass, $because))
)
);
}
}
}