FormShieldReportBuilder::withVerificationStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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