Completed
Push — master ( b91027...e2996f )
by Randy
02:17 queued 25s
created

XmlElement::accept()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dgame\Soap\Element;
4
5
use Dgame\Soap\PrefixableInterface;
6
use Dgame\Soap\PrefixTrait;
7
use Dgame\Soap\Visitor\ElementVisitorInterface;
8
9
/**
10
 * Class XmlElement
11
 * @package Dgame\Soap\element
12
 */
13
class XmlElement extends Element implements PrefixableInterface
14
{
15
    use PrefixTrait;
16
17
    /**
18
     * XmlElement constructor.
19
     *
20
     * @param string      $name
21
     * @param string|null $value
22
     * @param string|null $prefix
23
     */
24
    public function __construct(string $name, string $value = null, string $prefix = null)
25
    {
26
        parent::__construct($name, $value);
27
28
        $this->prefix = $prefix;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    final public function getNamespace(): string
35
    {
36
        if ($this->hasPrefix()) {
37
            return sprintf('%s:%s', $this->getPrefix(), $this->getName());
38
        }
39
40
        return $this->getName();
41
    }
42
43
    /**
44
     * @param PrefixableInterface $prefixable
45
     */
46
    final public function inheritPrefix(PrefixableInterface $prefixable)
47
    {
48
        if (!$this->hasPrefix() && $prefixable->hasPrefix()) {
49
            $this->prefix = $prefixable->getPrefix();
50
            $prefixable->prefixUsedBy($this);
51
        }
52
    }
53
54
    /**
55
     * @param ElementVisitorInterface $visitor
56
     */
57
    public function accept(ElementVisitorInterface $visitor)
58
    {
59
        $visitor->visitXmlElement($this);
60
    }
61
62
    /**
63
     * @param Element $element
64
     */
65
    public function prefixUsedBy(Element $element)
66
    {
67
    }
68
}