Passed
Push — master ( f54444...bb44e9 )
by Sergey
02:48
created

ErrorsStore::iterate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * @author: Viskov Sergey
4
 * @date  : 4/12/16
5
 * @time  : 1:00 PM
6
 */
7
8
namespace LTDBeget\dns\configurator\errors;
9
10
/**
11
 * Class ErrorsStore
12
 *
13
 * @package LTDBeget\dns\configurator\errors
14
 */
15
class ErrorsStore
16
{
17
    /**
18
     * @var ValidationError[]
19
     */
20
    private $errors = [];
21
22
    /**
23
     * @return ErrorsStore
24
     */
25 1
    public function clear() : ErrorsStore
26
    {
27 1
        $this->errors = [];
28
29 1
        return $this;
30
    }
31
32
    /**
33
     * @param ValidationError $error
34
     */
35 1
    public function add(ValidationError $error)
36
    {
37 1
        $this->errors[] = $error;
38 1
    }
39
40
    /**
41
     * @return bool
42
     */
43 1
    public function isHasErrors() : bool
44
    {
45 1
        return count($this->errors) > 0;
46
    }
47
48
    /**
49
     * @return ValidationError[]
50
     */
51
    public function iterate()
52
    {
53
        foreach ($this->errors as $error) {
54
            yield $error;
55
        }
56
    }
57
58
    /**
59
     * @return array
60
     */
61
    public function toArray() : array
62
    {
63
        $errorsAsArray = [];
64
        foreach ($this->errors as $error) {
65
            $errorsAsArray[] = $error->toArray();
66
        }
67
68
        return $errorsAsArray;
69
    }
70
}