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

NodeScalarValue::createEventIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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