Passed
Push — master ( 7065f2...e55ca3 )
by Edward
03:45
created

InvalidNodeDataException   A

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