Completed
Push — master ( c6e2ca...b2d8c9 )
by Tony
09:34
created

MissingConfigException::getKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ClassConfig\Exceptions;
4
5
/**
6
 * Class MissingConfigException
7
 * @package ClassConfig\Exceptions
8
 */
9
class MissingConfigException extends \RuntimeException
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $key;
15
16
    /**
17
     * @var string[]
18
     */
19
    protected $trail;
20
21
    /**
22
     * MissingConfigException constructor.
23
     *
24
     * @param string[] $trail
25
     */
26
    public function __construct(array $trail)
27
    {
28
        $this->key = array_pop($trail);
29
        $this->trail = $trail;
30
31
        parent::__construct(sprintf(
32
            'Missing required config entry: "%s"%s.',
33
            $this->key,
34
            0 < count($this->trail) ? sprintf(' (%s)', implode('.', array_merge($this->trail, [$this->key]))) : ''
35
        ));
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getKey(): string
42
    {
43
        return $this->key;
44
    }
45
46
    /**
47
     * @return string[]
48
     */
49
    public function getTrail(): array
50
    {
51
        return $this->trail;
52
    }
53
}