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

XmlElement   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getNamespace() 0 8 2
A inheritPrefix() 0 7 3
A accept() 0 4 1
A prefixUsedBy() 0 3 1
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
}