Completed
Push — master ( 56a459...0ee720 )
by Randy
03:34
created

Element::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Dgame\Soap;
4
5
use Dgame\Soap\Hydrator\HydratorInterface;
6
use Dgame\Soap\Hydrator\HydrateInterface;
7
use Dgame\Soap\Attribute\Attribute;
8
9
/**
10
 * Class Element
11
 * @package Dgame\Soap
12
 */
13
class Element implements HydrateInterface
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
    public function __construct(string $name, string $value = null)
35
    {
36
        $this->name = $name;
37
        if ($value !== null) {
38
            $this->setValue($value);
39
        }
40
    }
41
42
    /**
43
     * @return null|string
44
     */
45
    final public function getValue(): ?string
46
    {
47
        return $this->value;
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    final public function hasValue(): bool
54
    {
55
        return $this->value !== null;
56
    }
57
58
    /**
59
     * @param string $value
60
     */
61
    final public function setValue(string $value)
62
    {
63
        $value = trim($value);
64
        if (strlen($value) !== 0) {
65
            $this->value = $value;
66
        }
67
    }
68
69
    /**
70
     * @param Attribute $attribute
71
     */
72
    final public function setAttribute(Attribute $attribute)
73
    {
74
        $this->attributes[] = $attribute;
75
    }
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
    final public function getAttributes(): array
92
    {
93
        return $this->attributes;
94
    }
95
96
    /**
97
     * @return bool
98
     */
99
    final public function hasAttributes(): bool
100
    {
101
        return !empty($this->attributes);
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    final public function getName(): string
108
    {
109
        return $this->name;
110
    }
111
112
    /**
113
     * @param HydratorInterface $hydrator
114
     */
115
    public function hydration(HydratorInterface $hydrator)
116
    {
117
        $hydrator->hydrateElement($this);
118
    }
119
}