Completed
Push — master ( ad24bf...d452c0 )
by Ricardo
168:19 queued 133:59
created

ErrorCollection::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace RicardoFiorani\Validator\Response\Error\Collection;
4
5
use RicardoFiorani\Validator\Response\Error\ValidationErrorInterface;
6
7
class ErrorCollection
8
{
9
    private $elements;
10
11 10
    public function __construct()
12
    {
13 10
        $this->elements = [];
14 10
    }
15
16 9
    public function toArray(): array
17
    {
18 9
        return $this->elements;
19
    }
20
21 1
    public function removeElement(ValidationErrorInterface $element): self
22
    {
23 1
        $key = array_search($element, $this->elements, true);
24
25 1
        if ($key !== false) {
26 1
            unset($this->elements[$key]);
27
        }
28
29 1
        return $this;
30
    }
31
32 7
    public function add(ValidationErrorInterface $element): self
33
    {
34 7
        $this->elements[] = $element;
35
36 7
        return $this;
37
    }
38
39 1
    public function clear(): self
40
    {
41 1
        $this->elements = [];
42
43 1
        return $this;
44
    }
45
}
46