Total Complexity | 6 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 1 | Features | 1 |
1 | <?php |
||
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 |
|
55 | } |
||
56 | } |
||
57 |