ValidationReportBuilder::withRuleViolation()   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\ValidationReportBuilderInterface;
6
use WebTheory\Saveyour\Contracts\Report\ValidationReportInterface;
7
use WebTheory\Saveyour\Report\ValidationReport;
8
9
class ValidationReportBuilder implements ValidationReportBuilderInterface
10
{
11
    protected bool $validationStatus;
12
13
    protected array $ruleViolations = [];
14
15
    /**
16
     * @return $this
17
     */
18 12
    public function withValidationStatus(bool $status): ValidationReportBuilderInterface
19
    {
20 12
        $this->validationStatus = $status;
21
22 12
        return $this;
23
    }
24
25
    /**
26
     * @return $this
27
     */
28 6
    public function withRuleViolation(string $violation): ValidationReportBuilderInterface
29
    {
30 6
        $this->ruleViolations[] = $violation;
31
32 6
        return $this;
33
    }
34
35
    /**
36
     * @return $this
37
     */
38
    public function withRuleViolations(array $violations): ValidationReportBuilderInterface
39
    {
40
        array_map([$this, 'withRuleViolation'], $violations);
41
42
        return $this;
43
    }
44
45 12
    public function build(): ValidationReportInterface
46
    {
47 12
        return new ValidationReport($this->validationStatus, ...$this->ruleViolations);
48
    }
49
}
50