Completed
Push — master ( fa6370...25cc22 )
by Eric
06:29
created

KeyIsNotDefinedException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Oqq\Minc\Common\Collection\Exception;
4
5
use Oqq\Minc\Common\Exception\OutOfBoundsException;
6
7
/**
8
 * @author Eric Braun <[email protected]>
9
 */
10
class KeyIsNotDefinedException extends OutOfBoundsException
11
{
12
    /** @var mixed */
13
    protected $key;
14
15
    /**
16
     * @param mixed $key
17
     */
18
    public function __construct($key)
19
    {
20
        $this->key = $key;
21
22
        parent::__construct(sprintf(
23
            'Key with value %s is not defined',
24
            $this->getKeyAsString()
25
        ));
26
    }
27
28
    /**
29
     * @return mixed
30
     */
31
    public function getKey()
32
    {
33
        return $this->key;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    protected function getKeyAsString()
40
    {
41
        return is_string($this->key) ? '"'.$this->key.'"' : var_export($this->key, true);
42
    }
43
}
44