Passed
Pull Request — 3.x (#348)
by
unknown
01:48
created

MultipleErrors::reason()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Egulias\EmailValidator\Result;
4
5
use Egulias\EmailValidator\Result\Reason\EmptyReason;
6
use Egulias\EmailValidator\Result\Reason\Reason;
7
8
/**
9
 * @psalm-suppress PropertyNotSetInConstructor
10
 */
11
class MultipleErrors extends InvalidEmail
12
{
13
    /**
14
     * @var Reason[]
15
     */
16
    private $reasons = [];
17
18 11
    public function __construct()
19
    {
20 11
    }
21
22 10
    public function addReason(Reason $reason) : void
23
    {
24 10
        $this->reasons[$reason->code()] = $reason;
25
    }
26
27
    /**
28
     * @return Reason[]
29
     */
30 2
    public function getReasons() : array
31
    {
32 2
        return $this->reasons;
33
    }
34
35 4
    public function reason() : Reason
36
    {
37 4
        return 0 !== count($this->reasons)
38 3
            ? current($this->reasons)
39 4
            : new EmptyReason();
40
    }
41
42 1
    public function description() : string
43
    {
44 1
        $description = '';
45 1
        foreach($this->reasons as $reason) {
46 1
            $description .= $reason->description() . PHP_EOL;
47
        }
48
49 1
        return $description;
50
    }
51
52
    public function code() : int
53
    {
54
        return 0;
55
    }
56
}
57