Test Failed
Push — master ( 3c2029...7a5756 )
by Randy
02:39
created

ElementPrefixInheritanceVisitor::inheritPrefix()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Dgame\Soap\Visitor;
4
5
use Dgame\Soap\Element;
6
use Dgame\Soap\XmlElement;
7
use Dgame\Soap\XmlNode;
8
9
/**
10
 * Class ElementPrefixInheritanceVisitor
11
 * @package Dgame\Soap\Visitor
12
 */
13
final class ElementPrefixInheritanceVisitor implements ElementVisitorInterface
14
{
15
    /**
16
     * @var XmlNode
17
     */
18
    private $node;
19
20
    /**
21
     * PrefixInheritanceVisitor constructor.
22
     *
23
     * @param XmlNode $node
24
     */
25
    public function __construct(XmlNode $node)
26
    {
27
        $this->node = $node;
28
    }
29
30
    /**
31
     * @param Element $element
32
     */
33
    public function visitElement(Element $element)
34
    {
35
    }
36
37
    /**
38
     * @param XmlElement $element
39
     */
40
    public function visitXmlElement(XmlElement $element)
41
    {
42
        $this->inheritPrefix($element);
43
    }
44
45
    /**
46
     * @param XmlNode $node
47
     */
48
    public function visitXmlNode(XmlNode $node)
49
    {
50
        $this->inheritPrefix($node);
51
    }
52
53
    /**
54
     * @param XmlElement $element
55
     */
56
    private function inheritPrefix(XmlElement $element)
57
    {
58
        if (!$element->hasPrefix() && $this->node->hasPrefix()) {
59
            $element->setPrefix($this->node->getPrefix());
60
        }
61
    }
62
}