Completed
Push — master ( 320901...7f6495 )
by Dawid
06:42
created

ValidationResult   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 53
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addViolation() 0 6 1
A isValid() 0 4 1
A getViolations() 0 4 1
A getIterator() 0 4 1
A count() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\Service\SchemaValidator;
6
7
class ValidationResult implements \IteratorAggregate, \Countable
8
{
9
    /**
10
     * @var ValidationViolation[]
11
     */
12
    protected $errors = [];
13
14
    /**
15
     * @param ValidationViolation $validationViolation
16
     *
17
     * @return ValidationResult
18
     */
19 3
    public function addViolation(ValidationViolation $validationViolation): self
20
    {
21 3
        $this->errors[] = $validationViolation;
22
23 3
        return $this;
24
    }
25
26
    /**
27
     * @return bool
28
     */
29 5
    public function isValid(): bool
30
    {
31 5
        return empty($this->errors);
32
    }
33
34
    /**
35
     * @return ValidationViolation[]
36
     */
37 1
    public function getViolations(): array
38
    {
39 1
        return $this->errors;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     *
45
     * @return \ArrayIterator|ValidationViolation[]
46
     */
47 1
    public function getIterator(): \ArrayIterator
48
    {
49 1
        return new \ArrayIterator($this->errors);
50
    }
51
52
    /**
53
     * {@inheritdoc.
54
     */
55 1
    public function count(): int
56
    {
57 1
        return \count($this->errors);
58
    }
59
}
60