ValidationReportBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 39
ccs 8
cts 11
cp 0.7272
rs 10
c 1
b 0
f 1
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withRuleViolations() 0 5 1
A build() 0 3 1
A withRuleViolation() 0 5 1
A withValidationStatus() 0 5 1
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