Completed
Push — master ( a9170f...6467e6 )
by Roman
19:21 queued 08:22
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 __construct() 0 15 1
A getNeedType() 0 3 1
A getVar() 0 3 1
1
<?php
2
3
namespace kartavik\Support\Exception;
4
5
use kartavik\Support\Exception;
6
7
/**
8
 * Class InvalidElementException
9
 * @package kartavik\Support\Exceptions
10
 */
11
class InvalidElement extends \InvalidArgumentException implements Exception
12
{
13
    /** @var mixed */
14
    protected $var;
15
16
    /** @var string */
17
    protected $needType;
18
19
    public function __construct(
20
        $var,
21
        string $needType,
22
        int $code = 0,
23
        \Throwable $previous = null
24
    ) {
25
        $this->var = $var;
26
        $this->needType = $needType;
27
28
        $objectType = get_class($var);
29
30
        parent::__construct(
31
            "Element {$objectType} must be instance of " . $needType,
32
            $code,
33
            $previous
34
        );
35
    }
36
37
    public function getVar()
38
    {
39
        return $this->var;
40
    }
41
42
    public function getNeedType(): string
43
    {
44
        return $this->needType;
45
    }
46
}
47