| Total Complexity | 5 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 | 7 | public function addViolation(ValidationViolation $validationViolation): self |
|
| 20 | { |
||
| 21 | 7 | $this->errors[] = $validationViolation; |
|
| 22 | |||
| 23 | 7 | return $this; |
|
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @return bool |
||
| 28 | */ |
||
| 29 | 7 | public function isValid(): bool |
|
| 30 | { |
||
| 31 | 7 | return empty($this->errors); |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return ValidationViolation[] |
||
| 36 | */ |
||
| 37 | 4 | public function getViolations(): array |
|
| 38 | { |
||
| 39 | 4 | 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 | 3 | public function count(): int |
|
| 58 | } |
||
| 59 | } |
||
| 60 |