Completed
Push — master ( cb0ced...7754cf )
by Edward
04:45
created

NodeScalarValue   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 3 1
A __construct() 0 7 3
A createGenerator() 0 3 1
A getPath() 0 3 1
A createEventIterator() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Data\Value\DecodedJson;
5
6
use Generator;
7
use Iterator;
8
use Remorhaz\JSON\Data\Event\ScalarEvent;
9
use Remorhaz\JSON\Data\Path\PathInterface;
10
use Remorhaz\JSON\Data\Value\NodeValueInterface;
11
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
12
13
final class NodeScalarValue implements NodeValueInterface, ScalarValueInterface
14
{
15
16
    private $data;
17
18
    private $path;
19
20 9
    public function __construct($data, PathInterface $path)
21
    {
22 9
        if (null !== $data && !is_scalar($data)) {
23 4
            throw new Exception\InvalidNodeDataException($data, $path);
24
        }
25 5
        $this->data = $data;
26 5
        $this->path = $path;
27 5
    }
28
29 5
    public function getData()
30
    {
31 5
        return $this->data;
32
    }
33
34 5
    public function getPath(): PathInterface
35
    {
36 5
        return $this->path;
37
    }
38
39 5
    public function createEventIterator(): Iterator
40
    {
41 5
        return $this->createGenerator();
42
    }
43
44 5
    private function createGenerator(): Generator
45
    {
46 5
        yield new ScalarEvent($this);
47 5
    }
48
}
49