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

XmlElement::setAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Dgame\Soap;
4
5
use Dgame\Soap\Attribute\Attribute;
6
use Dgame\Soap\Visitor\AttributePrefixInheritanceVisitor;
7
use Dgame\Soap\Visitor\ElementVisitorInterface;
8
9
/**
10
 * Class XmlElement
11
 * @package Dgame\Soap
12
 */
13
class XmlElement extends Element implements PrefixableInterface
14
{
15
    /**
16
     * @var null|string
17
     */
18
    private $prefix;
19
20
    /**
21
     * XmlElement constructor.
22
     *
23
     * @param string      $name
24
     * @param string|null $prefix
25 14
     * @param string|null $value
26
     */
27 14
    public function __construct(string $name, string $prefix = null, string $value = null)
28
    {
29 14
        parent::__construct($name, $value);
30 14
31
        $this->prefix = $prefix;
32 14
    }
33
34
    /**
35
     * @param Attribute $attribute
36
     */
37 7
    public function setAttribute(Attribute $attribute)
38
    {
39 7
        parent::setAttribute($attribute);
40
41
        $attribute->accept(new AttributePrefixInheritanceVisitor($this));
42
    }
43
44
    /**
45 14
     * @return bool
46
     */
47 14
    final public function hasPrefix(): bool
48
    {
49
        return !empty($this->prefix);
50
    }
51
52
    /**
53 14
     * @return string
54
     */
55 14
    final public function getPrefix(): string
56 14
    {
57 8
        return $this->prefix;
58
    }
59 14
60
    /**
61
     * @param string $prefix
62
     */
63
    public function setPrefix(string $prefix)
64 5
    {
65
        $this->prefix = $prefix;
66 5
    }
67 5
68 4
    /**
69
     * @return string
70
     */
71 1
    final public function getPrefixedName(): string
72
    {
73
        if ($this->hasPrefix()) {
74
            return sprintf('%s:%s', $this->getPrefix(), $this->getName());
75
        }
76
77 11
        return $this->getName();
78
    }
79 11
80 11
    /**
81
     * @param ElementVisitorInterface $visitor
82
     */
83
    public function accept(ElementVisitorInterface $visitor)
84
    {
85
        $visitor->visitXmlElement($this);
86
    }
87
}