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

NodeObjectValue::getPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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