Passed
Pull Request — master (#320)
by Dmitriy
12:15 queued 09:25
created

Error::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 3
c 1
b 1
f 1
nc 1
nop 3
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
final class Error
8
{
9
    private string $message;
10
11
    /**
12
     * @psalm-var list<int|string>
13
     */
14
    private array $valuePath;
15
    /**
16
     * @psalm-var list<int|string>
17
     */
18
    private array $parameters;
19
20
    /**
21
     * @psalm-param list<int|string> $valuePath
22
     */
23 372
    public function __construct(string $message, array $valuePath = [], array $parameters = [])
24
    {
25 372
        $this->message = $message;
26 372
        $this->valuePath = $valuePath;
27 372
        $this->parameters = $parameters;
28
    }
29
30 85
    public function getMessage(): string
31
    {
32 85
        return $this->message;
33
    }
34
35
    /**
36
     * @psalm-return list<int|string>
37
     */
38 87
    public function getValuePath(bool $escape = false): array
39
    {
40 87
        if ($escape === false) {
41 83
            return $this->valuePath;
42
        }
43
44 25
        return array_map(
45 25
            static fn ($key): string => str_replace(['.', '*'], ['\\' . '.', '\\' . '*'], (string)$key),
46 25
            $this->valuePath
47
        );
48
    }
49
50 83
    public function getParameters(): array
51
    {
52 83
        return $this->parameters;
53
    }
54
}
55