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

LiteralScalarValue::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Value;
5
6
use Generator;
7
use function is_scalar;
8
use Iterator;
9
use Remorhaz\JSON\Data\Event;
10
use Remorhaz\JSON\Data\Value\ScalarValueInterface;
11
12
final class LiteralScalarValue implements LiteralValueInterface, ScalarValueInterface
13
{
14
15
    private $data;
16
17 8
    public function __construct($data)
18
    {
19 8
        if (null !== $data && !is_scalar($data)) {
20 1
            throw new Exception\InvalidScalarDataException($data);
21
        }
22 7
        $this->data = $data;
23 7
    }
24
25 7
    public function getData()
26
    {
27 7
        return $this->data;
28
    }
29
30 1
    public function createEventIterator(): Iterator
31
    {
32 1
        return $this->createGenerator();
33
    }
34
35 1
    private function createGenerator(): Generator
36
    {
37 1
        yield new Event\ScalarEvent($this);
38 1
    }
39
}
40