Passed
Pull Request — master (#320)
by Dmitriy
02:58
created

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