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

Result   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 39
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 3 1
A addError() 0 3 1
A getErrors() 0 7 1
A getRawErrors() 0 3 1
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