Passed
Pull Request — master (#151)
by
unknown
02:14
created

Result::addError()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 4
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
final class Result
8
{
9
    /**
10
     * @psalm-var list<int|string, string>
11
     */
12
    private array $errors = [];
13
14 158
    public function isValid(): bool
15
    {
16 158
        return $this->errors === [];
17
    }
18
19
    /**
20
     * @param string $message
21
     * @param int|string|null $key
22
     * @return void
23
     */
24 128
    public function addError(string $message, $key = null): void
25
    {
26 128
        if ($key !== null && $key !== 0) {
27 5
            $this->errors[$key] = $message;
28
        } else {
29 128
            $this->errors[] = $message;
30
        }
31 128
    }
32
33
    /**
34
     * @psalm-return list<int|string, string>
35
     */
36 36
    public function getErrors(): array
37
    {
38 36
        return $this->errors;
39
    }
40
}
41