Passed
Push — master ( 5f88dd...10f6bc )
by Smoren
12:50
created

PathException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 7
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Smoren\Schemator\Exceptions;
4
5
abstract class PathException extends \OutOfBoundsException
6
{
7
    /**
8
     * @var string
9
     */
10
    protected string $key;
11
    /**
12
     * @var string[]
13
     */
14
    protected array $path;
15
    /**
16
     * @var non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
17
     */
18
    protected string $pathDelimiter;
19
20
    /**
21
     * @param string $key
22
     * @param string[] $path
23
     * @param non-empty-string $pathDelimiter
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
24
     */
25
    public function __construct(string $key, array $path, string $pathDelimiter)
26
    {
27
        parent::__construct();
28
        $this->key = $key;
29
        $this->path = $path;
30
        $this->pathDelimiter = $pathDelimiter;
31
        parent::__construct("Key '{$this->key}' is not found on path '{$this->getPathString()}'");
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getKey(): string
38
    {
39
        return $this->key;
40
    }
41
42
    /**
43
     * @return string[]
44
     */
45
    public function getPath(): array
46
    {
47
        return $this->path;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getPathString(): string
54
    {
55
        return implode($this->pathDelimiter, $this->getPath());
56
    }
57
}
58