XmlElement   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 68
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getPrefixedName() 0 8 2
A setPrefix() 0 7 2
A hasPrefix() 0 4 1
A getPrefix() 0 4 1
A accept() 0 4 1
1
<?php
2
3
namespace Dgame\Soap;
4
5
use Dgame\Soap\Visitor\ElementVisitorInterface;
6
7
/**
8
 * Class XmlElement
9
 * @package Dgame\Soap
10
 */
11
class XmlElement extends Element
12
{
13
    /**
14
     * @var string
15
     */
16
    private $prefix;
17
18
    /**
19
     * XmlElement constructor.
20
     *
21
     * @param string      $name
22
     * @param string|null $value
23
     * @param string|null $prefix
24
     */
25 16
    public function __construct(string $name, string $value = null, string $prefix = null)
26
    {
27 16
        parent::__construct($name, $value);
28
29 16
        $this->setPrefix($prefix ?? '');
30 16
    }
31
32 16
    /**
33
     * @return string
34
     */
35
    final public function getPrefixedName(): string
36
    {
37 16
        if ($this->hasPrefix()) {
38
            return sprintf('%s:%s', $this->prefix, $this->getName());
39 16
        }
40
41
        return $this->getName();
42
    }
43
44
    /**
45 7
     * @param string $prefix
46
     */
47 7
    public function setPrefix(string $prefix)
48
    {
49
        $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...
50
        if (strlen($prefix) !== 0) {
51
            $this->prefix = $prefix;
52
        }
53 16
    }
54
55 16
    /**
56 16
     * @return bool
57
     */
58
    final public function hasPrefix(): bool
59
    {
60
        return $this->prefix !== null;
61 5
    }
62
63 5
    /**
64 4
     * @return string
65
     */
66
    final public function getPrefix(): string
67 1
    {
68
        return $this->prefix;
69
    }
70
71
    /**
72
     * @param ElementVisitorInterface $visitor
73 15
     */
74
    public function accept(ElementVisitorInterface $visitor)
75 15
    {
76 15
        $visitor->visitXmlElement($this);
77
    }
78
}