Passed
Push — master ( 7065f2...e55ca3 )
by Edward
03:45
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\Path\PathAwareInterface;
9
use Remorhaz\JSON\Data\Path\PathInterface;
10
use RuntimeException;
11
use Throwable;
12
13
class InvalidNodeDataException extends RuntimeException implements
14
    ExceptionInterface,
15
    PathAwareInterface,
16
    DataAwareInterface
17
{
18
19
    private $data;
20
21
    private $path;
22
23
    public function __construct($data, PathInterface $path, Throwable $previous = null)
24
    {
25
        $this->data = $data;
26
        $this->path = $path;
27
        parent::__construct($this->buildMessage(), 0, $previous);
28
    }
29
30
    private function buildMessage(): string
31
    {
32
        return "Invalid data in decoded JSON at {$this->buildPath()}";
33
    }
34
35
    public function getData()
36
    {
37
        return $this->data;
38
    }
39
40
    public function getPath(): PathInterface
41
    {
42
        return $this->path;
43
    }
44
45
    private function buildPath(): string
46
    {
47
        return '/' . implode('/', $this->path->getElements());
48
    }
49
}
50