Code Duplication    Length = 29-29 lines in 2 locations

src/NodeToArray/AttributeNodeToArrayHandler.php 1 location

@@ 8-36 (lines=29) @@
5
use Saxulum\JsonDocument\AbstractNode;
6
use Saxulum\JsonDocument\AttributeNode;
7
8
class AttributeNodeToArrayHandler extends AbstractNodeToArrayHandler
9
{
10
    /**
11
     * @param  AbstractNode $node
12
     * @param  bool         $embedded
13
     * @return array
14
     */
15
    public function getArray(AbstractNode $node, $embedded = false)
16
    {
17
        if (!$node instanceof AttributeNode) {
18
            throw new \InvalidArgumentException("Invalid node type!");
19
        }
20
21
        if (!$embedded) {
22
            return array($node->getFormattedName() => $node->getValue());
23
        }
24
25
        return $node->getValue();
26
    }
27
28
    /**
29
     * @param  AbstractNode $node
30
     * @return bool
31
     */
32
    public function isResponsible(AbstractNode $node)
33
    {
34
        return $node instanceof AttributeNode;
35
    }
36
}
37

src/NodeToArray/ValueNodeToArrayHandler.php 1 location

@@ 8-36 (lines=29) @@
5
use Saxulum\JsonDocument\AbstractNode;
6
use Saxulum\JsonDocument\ValueNode;
7
8
class ValueNodeToArrayHandler extends AbstractNodeToArrayHandler
9
{
10
    /**
11
     * @param  AbstractNode $node
12
     * @param  bool         $embedded
13
     * @return array
14
     */
15
    public function getArray(AbstractNode $node, $embedded = false)
16
    {
17
        if (!$node instanceof ValueNode) {
18
            throw new \InvalidArgumentException("Invalid node type!");
19
        }
20
21
        if (!$embedded) {
22
            return array($node->getName() => $node->getValue());
23
        }
24
25
        return $node->getValue();
26
    }
27
28
    /**
29
     * @param  AbstractNode $node
30
     * @return bool
31
     */
32
    public function isResponsible(AbstractNode $node)
33
    {
34
        return $node instanceof ValueNode;
35
    }
36
}
37