InvalidNodeDataException::buildMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Data\Value\DecodedJson\Exception;
6
7
use Remorhaz\JSON\Data\Value\DataAwareInterface;
8
use Remorhaz\JSON\Data\Exception\ExceptionInterface;
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
    private $data;
21
22
    private $path;
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
    public function getPath(): PathInterface
42
    {
43
        return $this->path;
44
    }
45
46
    private function buildPath(): string
47
    {
48
        return '/' . implode('/', $this->path->getElements());
49
    }
50
}
51