Passed
Push — master ( 5c2907...37dc07 )
by Sergei
24:35 queued 21:56
created

Error   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 5
eloc 8
c 1
b 1
f 1
dl 0
loc 45
ccs 11
cts 11
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getParameters() 0 3 1
A getMessage() 0 3 1
A __construct() 0 13 1
A getValuePath() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator;
6
7
final class Error
8
{
9
    /**
10
     * @psalm-param list<int|string> $valuePath
11
     */
12 384
    public function __construct(
13
        private string $message,
14
15
        /**
16
         * @psalm-var array<string,scalar|null>
17
         */
18
        private array $parameters = [],
19
20
        /**
21
         * @psalm-var list<int|string>
22
         */
23
        private array $valuePath = [],
24
    ) {
25
    }
26
27 380
    public function getMessage(): string
28
    {
29 380
        return $this->message;
30
    }
31
32
    /**
33
     * @psalm-return array<string,scalar|null>
34
     */
35 373
    public function getParameters(): array
36
    {
37 373
        return $this->parameters;
38
    }
39
40
    /**
41
     * @psalm-return list<int|string>
42
     */
43 382
    public function getValuePath(bool $escape = false): array
44
    {
45 382
        if ($escape === false) {
46 380
            return $this->valuePath;
47
        }
48
49 314
        return array_map(
50 314
            static fn ($key): string => str_replace(['.', '*'], ['\\' . '.', '\\' . '*'], (string) $key),
51 314
            $this->valuePath
52
        );
53
    }
54
}
55