InvalidAttributeException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\UniLex\AST\Exception;
6
7
use DomainException;
8
use Throwable;
9
10
use function gettype;
11
12
final class InvalidAttributeException extends DomainException implements ExceptionInterface
13
{
14
    private $name;
15
16
    private $value;
17
18
    private $expectedType;
19
20
    public function __construct(string $name, $value, string $expectedType, Throwable $previous = null)
21
    {
22
        $this->name = $name;
23
        $this->value = $value;
24
        $this->expectedType = $expectedType;
25
        $actualType = gettype($this->value);
26
        parent::__construct(
27
            "Node attribute '{$this->name}' has invalid type: {$actualType} instead of expected {$this->expectedType}",
28
            0,
29
            $previous
30
        );
31
    }
32
}
33