Test Failed
Push — master ( 3c2029...7a5756 )
by Randy
02:39
created

Element::setAttributes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
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 14
    public function __construct(string $name, string $value = null)
35
    {
36 14
        $this->name = $name;
37 14
38 14
        if ($value !== null) {
39
            $this->setValue($value);
40 14
        }
41
    }
42
43
    /**
44
     * @return string
45 13
     */
46
    final public function getName(): string
47 13
    {
48
        return $this->name;
49
    }
50
51
    /**
52
     * @return bool
53 14
     */
54
    final public function hasValue(): bool
55 14
    {
56
        return !empty($this->value);
57
    }
58
59
    /**
60
     * @param string $value
61 14
     */
62
    final public function setValue(string $value)
63 14
    {
64 14
        $this->value = trim($value);
65 13
    }
66
67 14
    /**
68
     * @return string
69
     */
70
    final public function getValue(): string
71
    {
72 12
        return $this->value;
73
    }
74 12
75 12
    /**
76
     * @param Attribute $attribute
77
     */
78
    public function setAttribute(Attribute $attribute)
79
    {
80
        $this->attributes[] = $attribute;
81
    }
82
83
    /**
84
     * @return bool
85
     */
86
    final public function hasAttributes(): bool
87
    {
88
        return !empty($this->attributes);
89
    }
90
91 14
    /**
92
     * @return Attribute[]
93 14
     */
94
    final public function getAttributes(): array
95
    {
96
        return $this->attributes;
97
    }
98
99 3
    /**
100
     * @param ElementVisitorInterface $visitor
101 3
     */
102
    public function accept(ElementVisitorInterface $visitor)
103
    {
104
        $visitor->visitElement($this);
105
    }
106
}