FormShieldReportBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 47
ccs 10
cts 15
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A withRuleViolations() 0 5 1
A withVerificationStatus() 0 5 1
A build() 0 3 1
A withRuleViolation() 0 5 1
1
<?php
2
3
namespace WebTheory\Saveyour\Report\Builder;
4
5
use WebTheory\Saveyour\Contracts\Report\Builder\FormShieldReportBuilderInterface;
6
use WebTheory\Saveyour\Contracts\Report\FormShieldReportInterface;
7
use WebTheory\Saveyour\Report\FormShieldReport;
8
9
class FormShieldReportBuilder implements FormShieldReportBuilderInterface
10
{
11
    protected bool $status;
12
13
    protected array $violations = [];
14
15 12
    public function __construct(FormShieldReportInterface $previous = null)
16
    {
17 12
        if ($previous) {
18
            $this->status = $previous->verificationStatus();
19
            $this->violations = $previous->ruleViolations();
20
        }
21
    }
22
23
    /**
24
     * @return $this
25
     */
26 12
    public function withVerificationStatus(bool $status): FormShieldReportBuilderInterface
27
    {
28 12
        $this->status = $status;
29
30 12
        return $this;
31
    }
32
33
    /**
34
     * @return $this
35
     */
36 6
    public function withRuleViolation(string $name): FormShieldReportBuilderInterface
37
    {
38 6
        $this->violations[] = $name;
39
40 6
        return $this;
41
    }
42
43
    /**
44
     * @return $this
45
     */
46
    public function withRuleViolations(array $violations): FormShieldReportBuilderInterface
47
    {
48
        $this->violations = $violations;
49
50
        return $this;
51
    }
52
53 12
    public function build(): FormShieldReportInterface
54
    {
55 12
        return new FormShieldReport($this->status, ...$this->violations);
56
    }
57
}
58