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

LiteralScalarValue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 3
A getData() 0 3 1
A createGenerator() 0 3 1
A createEventIterator() 0 3 1
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