Passed
Push — master ( 76b76b...ca78d8 )
by Edward
02:11
created

InvalidNodeDataException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Data\Value\DecodedJson\Exception;
5
6
use Remorhaz\JSON\Data\Value\DataAwareInterface;
7
use Remorhaz\JSON\Data\Exception\ExceptionInterface;
8
use Remorhaz\JSON\Data\Exception\PathAwareExceptionTrait;
9
use Remorhaz\JSON\Data\Path\PathAwareInterface;
10
use Remorhaz\JSON\Data\Path\PathInterface;
11
use RuntimeException;
12
use Throwable;
13
14
class InvalidNodeDataException extends RuntimeException implements
15
    ExceptionInterface,
16
    PathAwareInterface,
17
    DataAwareInterface
18
{
19
20
    use PathAwareExceptionTrait;
21
22
    private $data;
23
24
    public function __construct($data, PathInterface $path, Throwable $previous = null)
25
    {
26
        $this->data = $data;
27
        $this->path = $path;
28
        parent::__construct($this->buildMessage(), 0, $previous);
29
    }
30
31
    private function buildMessage(): string
32
    {
33
        return "Invalid data in decoded JSON at {$this->buildPath()}";
34
    }
35
36
    public function getData()
37
    {
38
        return $this->data;
39
    }
40
}
41