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

Element::hasAttributes()   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\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
}