Passed
Push — master ( 30ecae...ce9923 )
by Roman
01:45
created

InvalidElement::getVar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kartavik\Collections\Exception;
4
5
/**
6
 * Class InvalidElementException
7
 * @package kartavik\Collections\Exceptions
8
 */
9
class InvalidElement extends \InvalidArgumentException
10
{
11
    /** @var mixed */
12
    protected $var;
13
14
    /** @var string */
15
    protected $needType;
16
17
    public function __construct(
18
        $var,
19
        string $needType,
20
        int $code = 0,
21
        \Throwable $previous = null
22
    ) {
23
        $this->var = $var;
24
        $this->needType = $needType;
25
26
        $objectType = get_class($var);
27
28
        parent::__construct(
29
            "Element {$objectType} must be instance of " . $needType,
30
            $code,
31
            $previous
32
        );
33
    }
34
35
    public function getVar()
36
    {
37
        return $this->var;
38
    }
39
40
    public function getNeedType(): string
41
    {
42
        return $this->needType;
43
    }
44
}
45