Passed
Push — master ( 37810d...c6a7a1 )
by Chris
03:03
created

SafeNodeFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 20
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createNodeFromValue() 0 15 4
1
<?php declare(strict_types=1);
2
3
namespace DaveRandom\Jom;
4
5
use DaveRandom\Jom\Exceptions\InvalidNodeValueException;
6
7
final class SafeNodeFactory extends NodeFactory
8
{
9
    /**
10
     * @inheritdoc
11
     */
12
    public function createNodeFromValue(Document $doc, $value): Node
13
    {
14
        if (null !== $node = $this->createScalarOrNullNodeFromValue($doc, $value)) {
15
            return $node;
16
        }
17
18
        if ($value instanceof \stdClass) {
19
            return $this->createObjectNodeFromStdClass($doc, $value);
20
        }
21
22
        if (\is_array($value)) {
23
            return $this->createArrayNodeFromPackedArray($doc, $value);
24
        }
25
26
        throw new InvalidNodeValueException("Failed to create node from value of type '" . \gettype($value) . "'");
27
    }
28
}
29