HaveNameMatchingRegEx   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 24
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A evaluate() 0 9 2
A __construct() 0 3 1
A describe() 0 3 1
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