HaveNameMatchingRegEx::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Architecture\Expression\ForClasses;
13
14
use Architecture\Analyzer\FullyQualifiedClassName;
15
use Arkitect\Analyzer\ClassDescription;
16
use Arkitect\Expression\Description;
17
use Arkitect\Expression\Expression;
18
use Arkitect\Expression\PositiveDescription;
19
use Arkitect\Rules\Violation;
20
use Arkitect\Rules\Violations;
21
22
class HaveNameMatchingRegEx implements Expression
23
{
24
    /** @var string */
25
    private $name;
26
27
    public function __construct(string $name)
28
    {
29
        $this->name = $name;
30
    }
31
32
    public function describe(ClassDescription $theClass): Description
33
    {
34
        return new PositiveDescription("should [have|not have] a name that matches {$this->name}");
35
    }
36
37
    public function evaluate(ClassDescription $theClass, Violations $violations): void
38
    {
39
        $fqcn = FullyQualifiedClassName::fromString($theClass->getFQCN());
40
        if (! $fqcn->classMatches($this->name)) {
41
            $violation = Violation::create(
42
                $theClass->getFQCN(),
43
                $this->describe($theClass)->toString()
44
            );
45
            $violations->add($violation);
46
        }
47
    }
48
}
49