Element::setValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Dgame\Soap;
4
5
use Dgame\Soap\Attribute\Attribute;
6
use Dgame\Soap\Visitor\ElementVisitorInterface;
7
8
/**
9
 * Class Element
10
 * @package Dgame\Soap
11
 */
12
class Element
13
{
14
    /**
15
     * @var string
16
     */
17
    private $name;
18
    /**
19
     * @var string
20
     */
21
    private $value;
22
    /**
23
     * @var Attribute[]
24
     */
25
    private $attributes = [];
26
27
    /**
28
     * Element constructor.
29
     *
30
     * @param string      $name
31
     * @param string|null $value
32
     */
33
    public function __construct(string $name, string $value = null)
34 16
    {
35
        $this->name = $name;
36 16
37
        $this->setValue($value ?? '');
38 16
    }
39 16
40
    /**
41 16
     * @return string
42
     */
43
    final public function getName(): string
44
    {
45
        return $this->name;
46 16
    }
47
48 16
    /**
49
     * @param string $value
50
     */
51
    final public function setValue(string $value)
52
    {
53
        $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...
54 16
        if (strlen($value) !== 0) {
55
            $this->value = $value;
56 16
        }
57
    }
58
59
    /**
60
     * @return bool
61
     */
62 16
    final public function hasValue(): bool
63
    {
64 16
        return $this->value !== null;
65 16
    }
66 14
67
    /**
68 16
     * @return string
69
     */
70
    final public function getValue(): string
71
    {
72
        return $this->value;
73 14
    }
74
75 14
    /**
76
     * @param Attribute $attribute
77
     */
78
    final public function setAttribute(Attribute $attribute)
79
    {
80
        $this->attributes[] = $attribute;
81 12
    }
82
83 12
    /**
84 12
     * @return bool
85
     */
86
    final public function hasAttributes(): bool
87
    {
88
        return !empty($this->attributes);
89 3
    }
90
91 3
    /**
92
     * @return Attribute[]
93
     */
94
    final public function getAttributes(): array
95
    {
96
        return $this->attributes;
97 16
    }
98
99 16
    /**
100
     * @param ElementVisitorInterface $visitor
101
     */
102
    public function accept(ElementVisitorInterface $visitor)
103
    {
104
        $visitor->visitElement($this);
105
    }
106
}