Passed
Pull Request — master (#99)
by Def
02:39
created

Result::getRawErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
final class Result
8
{
9
    /**
10
     * @var ErrorMessage[]
11
     */
12
    private array $errors = [];
13
14 137
    public function isValid(): bool
15
    {
16 137
        return $this->errors === [];
17
    }
18
19 120
    public function addError(ErrorMessage $error): void
20
    {
21 120
        $this->errors[] = $error;
22 120
    }
23
24
    /**
25
     * @param ErrorMessageFormatterInterface|null $formatter
26
     *
27
     * @return ErrorMessage[]
28
     */
29 18
    public function getRawErrors(): array
30
    {
31 18
        return $this->errors;
32
    }
33
34
    /**
35
     * @param ErrorMessageFormatterInterface|null $formatter
36
     *
37
     * @return string[]
38
     */
39 29
    public function getErrors(?ErrorMessageFormatterInterface $formatter = null): array
40
    {
41 29
        return array_map(
42 29
            function ($error) use ($formatter) {
43 26
                return $error->getFormattedMessage($formatter);
44 29
            },
45 29
            $this->errors
46
        );
47
    }
48
}
49