-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathArchRule.php
More file actions
63 lines (49 loc) · 1.4 KB
/
ArchRule.php
File metadata and controls
63 lines (49 loc) · 1.4 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
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace Arkitect\Rules;
use Arkitect\Analyzer\ClassDescription;
class ArchRule implements DSL\ArchRule
{
/** @var Specs */
private $thats;
/** @var Constraints */
private $shoulds;
/** @var string */
private $because;
/** @var array */
private $classesToBeExcluded;
/** @var bool */
private $runOnlyThis;
public function __construct(
Specs $specs,
Constraints $constraints,
string $because,
array $classesToBeExcluded,
bool $runOnlyThis
) {
$this->thats = $specs;
$this->shoulds = $constraints;
$this->because = $because;
$this->classesToBeExcluded = $classesToBeExcluded;
$this->runOnlyThis = $runOnlyThis;
}
public function check(ClassDescription $classDescription, Violations $violations): void
{
if ($classDescription->namespaceMatchesOneOfTheseNamespacesSplat(...$this->classesToBeExcluded)) {
return;
}
if (!$this->thats->allSpecsAreMatchedBy($classDescription, $this->because)) {
return;
}
$this->shoulds->checkAll($classDescription, $violations, $this->because);
}
public function isRunOnlyThis(): bool
{
return $this->runOnlyThis;
}
public function runOnlyThis(): DSL\ArchRule
{
$this->runOnlyThis = true;
return $this;
}
}