Completed
Push — master ( ad3f3f...b283b6 )
by Randy
02:33
created

XmlAttribute::setPrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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