Completed
Push — master ( ad3f3f...b283b6 )
by Randy
02:33
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 Method

Rating   Name   Duplication   Size   Complexity  
A XmlElement::hasPrefix() 0 4 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 $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 bool
38
     */
39 13
    final public function hasPrefix(): bool
40
    {
41 13
        return !empty($this->prefix);
42
    }
43
44
    /**
45
     * @return string
46
     */
47 7
    final public function getPrefix(): string
48
    {
49 7
        return $this->prefix;
50
    }
51
52
    /**
53
     * @param string $prefix
54
     */
55 13
    public function setPrefix(string $prefix)
56
    {
57 13
        $this->prefix = trim($prefix);
58 13
    }
59
60
    /**
61
     * @return string
62
     */
63 5
    final public function getPrefixedName(): string
64
    {
65 5
        if ($this->hasPrefix()) {
66 4
            return sprintf('%s:%s', $this->getPrefix(), $this->getName());
67
        }
68
69 1
        return $this->getName();
70
    }
71
72
    /**
73
     * @param ElementVisitorInterface $visitor
74
     */
75 12
    public function accept(ElementVisitorInterface $visitor)
76
    {
77 12
        $visitor->visitXmlElement($this);
78
    }
79
}