ValidationResultSet   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 46
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A isOk() 0 9 3
A isEmpty() 0 3 1
A getErrors() 0 8 2
A validationResults() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation;
5
6
/**
7
 * Composite
8
 */
9
class ValidationResultSet implements Result
10
{
11
    /** @var ValidationResult[] */
12
    private array $validationResults = [];
13
14
    public function add(ValidationResult ...$errorResult): self
15
    {
16
        array_push($this->validationResults, ...$errorResult);
17
        return $this;
18
    }
19
20
    /**
21
     * @inheritDoc
22
     */
23
    public function isOk(): bool
24
    {
25
        foreach ($this->validationResults as $violation) {
26
            if (!$violation->isOk()) {
27
                return false;
28
            }
29
        }
30
31
        return true;
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public function getErrors(): array
38
    {
39
        $errors = [];
40
        foreach ($this->validationResults as $violation) {
41
            array_push($errors, ...$violation->getErrors());
42
        }
43
44
        return $errors;
45
    }
46
47
    public function validationResults(): array
48
    {
49
        return $this->validationResults;
50
    }
51
52
    public function isEmpty(): bool
53
    {
54
        return empty($this->validationResults);
55
    }
56
}
57