Passed
Pull Request — master (#320)
by Dmitriy
02:36
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
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 function ($key): string {
46 24
                return str_replace(['.', '*'], ['\\' . '.', '\\' . '*'], (string)$key);
47
            },
48 25
            $this->valuePath
49
        );
50
    }
51
52 83
    public function getParameters(): array
53
    {
54 83
        return $this->parameters;
55
    }
56
}
57