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

Element   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 88.46%

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 1
dl 0
loc 97
ccs 23
cts 26
cp 0.8846
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getName() 0 4 1
A hasValue() 0 4 1
A setValue() 0 7 2
A getValue() 0 4 1
A setAttribute() 0 4 1
A hasAttributes() 0 4 1
A getAttributes() 0 4 1
A accept() 0 4 1
1
<?php
2
3
namespace Dgame\Soap;
4
5
use Dgame\Soap\Attribute\Attribute;
6
use Dgame\Soap\Visitor\ElementVisitableInterface;
7
use Dgame\Soap\Visitor\ElementVisitorInterface;
8
9
/**
10
 * Class Element
11
 * @package Dgame\Soap
12
 */
13
class Element implements ElementVisitableInterface, AssignableInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $name;
19
    /**
20
     * @var string
21
     */
22
    private $value;
23
    /**
24
     * @var Attribute[]
25
     */
26
    private $attributes = [];
27
28
    /**
29
     * Element constructor.
30
     *
31
     * @param string      $name
32
     * @param string|null $value
33
     */
34 13
    public function __construct(string $name, string $value = null)
35
    {
36 13
        $this->name = $name;
37
38 13
        if ($value !== null) {
39 13
            $this->setValue($value);
40
        }
41 13
    }
42
43
    /**
44
     * @return string
45
     */
46 13
    final public function getName(): string
47
    {
48 13
        return $this->name;
49
    }
50
51
    /**
52
     * @return bool
53
     */
54 13
    final public function hasValue(): bool
55
    {
56 13
        return $this->value !== null;
57
    }
58
59
    /**
60
     * @param string $value
61
     */
62 13
    final public function setValue(string $value)
63
    {
64 13
        $value = trim($value);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $value. This often makes code more readable.
Loading history...
65 13
        if (strlen($value) !== 0) {
66 12
            $this->value = $value;
67
        }
68 13
    }
69
70
    /**
71
     * @return string
72
     */
73 12
    final public function getValue(): string
74
    {
75 12
        return $this->value;
76
    }
77
78
    /**
79
     * @param Attribute $attribute
80
     */
81 11
    final public function setAttribute(Attribute $attribute)
82
    {
83 11
        $this->attributes[] = $attribute;
84 11
    }
85
86
    /**
87
     * @return bool
88
     */
89 3
    final public function hasAttributes(): bool
90
    {
91 3
        return !empty($this->attributes);
92
    }
93
94
    /**
95
     * @return Attribute[]
96
     */
97 13
    final public function getAttributes(): array
98
    {
99 13
        return $this->attributes;
100
    }
101
102
    /**
103
     * @param ElementVisitorInterface $visitor
104
     */
105
    public function accept(ElementVisitorInterface $visitor)
106
    {
107
        $visitor->visitElement($this);
108
    }
109
}