ValidationResultSet::isEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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