InvalidNodeDataException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 35
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getData() 0 3 1
A buildMessage() 0 3 1
A buildPath() 0 3 1
A getPath() 0 3 1
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