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

InvalidElement   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getNeedType() 0 3 1
A __construct() 0 15 1
A getVar() 0 3 1
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