Passed
Push — master ( c69a90...df5d45 )
by Edward
04:44
created

NodeObjectValue::createEventGenerator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
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\Value\ObjectValueInterface;
9
use Remorhaz\JSON\Data\Path\PathInterface;
10
use Remorhaz\JSON\Data\Value\NodeValueInterface;
11
use stdClass;
12
13
final class NodeObjectValue implements NodeValueInterface, ObjectValueInterface
14
{
15
16
    private $data;
17
18
    private $path;
19
20
    private $valueFactory;
21
22
    public function __construct(
23
        stdClass $data,
24
        PathInterface $path,
25
        NodeValueFactoryInterface $valueFactory
26
    ) {
27
        $this->data = $data;
28
        $this->path = $path;
29
        $this->valueFactory = $valueFactory;
30
    }
31
32
    public function createChildIterator(): Iterator
33
    {
34
        return $this->createChildGenerator();
35
    }
36
37
    private function createChildGenerator(): Generator
38
    {
39
        foreach (get_object_vars($this->data) as $name => $property) {
40
            yield $name => $this
41
                ->valueFactory
42
                ->createValue($property, $this->path->copyWithProperty($name));
43
        }
44
    }
45
46
    public function getPath(): PathInterface
47
    {
48
        return $this->path;
49
    }
50
}
51