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

ErrorsStore::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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
}