PathException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
dl 0
loc 51
rs 10
c 1
b 0
f 1
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 3 1
A getPathString() 0 3 1
A getPath() 0 3 1
A __construct() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Schemator\Exceptions;
6
7
abstract class PathException extends \OutOfBoundsException
8
{
9
    /**
10
     * @var string
11
     */
12
    protected string $key;
13
    /**
14
     * @var string[]
15
     */
16
    protected array $path;
17
    /**
18
     * @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...
19
     */
20
    protected string $pathDelimiter;
21
22
    /**
23
     * @param string $key
24
     * @param string[] $path
25
     * @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...
26
     */
27
    public function __construct(string $key, array $path, string $pathDelimiter)
28
    {
29
        parent::__construct();
30
        $this->key = $key;
31
        $this->path = $path;
32
        $this->pathDelimiter = $pathDelimiter;
33
        parent::__construct("Key '{$this->key}' is not found in path '{$this->getPathString()}'");
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function getKey(): string
40
    {
41
        return $this->key;
42
    }
43
44
    /**
45
     * @return string[]
46
     */
47
    public function getPath(): array
48
    {
49
        return $this->path;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getPathString(): string
56
    {
57
        return implode($this->pathDelimiter, $this->getPath());
58
    }
59
}
60