Completed
Push — master ( 126b63...733cbc )
by Randy
04:39
created

Element::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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