Completed
Push — master ( 126b63...733cbc )
by Randy
04:39
created

XmlElement::getPrefixedName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 0
crap 3
1
<?php
2
3
namespace Dgame\Soap;
4
5
use Dgame\Soap\Attribute\Attribute;
6
use Dgame\Soap\Attribute\XmlAttribute;
7
use Dgame\Soap\Hydrator\VisitorInterface;
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 $value
25
     * @param string|null $prefix
26
     */
27 13
    public function __construct(string $name, string $value = null, string $prefix = null)
28
    {
29 13
        parent::__construct($name, $value);
30
31 13
        if ($prefix !== null) {
32 13
            $this->setPrefix($prefix);
33
        }
34 13
    }
35
36
    /**
37
     * @return string
38
     */
39 7
    final public function getPrefix(): string
40
    {
41 7
        return $this->prefix;
42
    }
43
44
    /**
45
     * @return bool
46
     */
47 13
    final public function hasPrefix(): bool
48
    {
49 13
        return $this->prefix !== null;
50
    }
51
52
    /**
53
     * @param string $prefix
54
     */
55 13
    public function setPrefix(string $prefix)
56
    {
57 13
        $prefix = trim($prefix);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $prefix. This often makes code more readable.
Loading history...
58 13
        if (strlen($prefix) !== 0) {
59 8
            $this->prefix = $prefix;
60
        }
61 13
    }
62
63
    /**
64
     * @return string
65
     */
66 5
    final public function getPrefixedName(): string
67
    {
68 5
        $name = $this->getName();
69 5
        if ($this->hasPrefix()) {
70 4
            return !empty($name) ? sprintf('%s:%s', $this->getPrefix(), $name) : $this->getPrefix();
71
        }
72
73 1
        return $name;
74
    }
75
76
    /**
77
     * @param VisitorInterface $visitor
78
     */
79 10
    public function accept(VisitorInterface $visitor)
80
    {
81 10
        $visitor->visitXmlElement($this);
82
    }
83
}