Passed
Push — master ( 52d18d...80d494 )
by Patrick
10:33
created

HaveNameMatchingRegEx::evaluate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 6
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Architecture\Expression\ForClasses;
4
5
use Arkitect\Analyzer\ClassDescription;
6
use Architecture\Analyzer\FullyQualifiedClassName;
7
use Arkitect\Expression\Description;
8
use Arkitect\Expression\Expression;
9
use Arkitect\Expression\PositiveDescription;
10
use Arkitect\Rules\Violation;
11
use Arkitect\Rules\Violations;
12
13
class HaveNameMatchingRegEx implements Expression
14
{
15
    /** @var string */
16
    private $name;
17
18
    public function __construct(string $name)
19
    {
20
        $this->name = $name;
21
    }
22
23
    public function describe(ClassDescription $theClass): Description
24
    {
25
        return new PositiveDescription("should [have|not have] a name that matches {$this->name}");
26
    }
27
28
    public function evaluate(ClassDescription $theClass, Violations $violations): void
29
    {
30
        $fqcn = FullyQualifiedClassName::fromString($theClass->getFQCN());
31
        if (!$fqcn->classMatches($this->name)) {
32
            $violation = Violation::create(
33
                $theClass->getFQCN(),
34
                $this->describe($theClass)->toString()
35
            );
36
            $violations->add($violation);
37
        }
38
    }
39
40
}
41