Test Failed
Push — master ( 75b28b...0c032b )
by Roman
03:23
created

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