Attribute::hasValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
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\Attribute;
4
5
use Dgame\Soap\Visitor\AttributeVisitableInterface;
6
use Dgame\Soap\Visitor\AttributeVisitorInterface;
7
8
/**
9
 * Class Attribute
10
 * @package Dgame\Soap\Attribute
11
 */
12
class Attribute implements AttributeVisitableInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $name;
18
    /**
19
     * @var string
20
     */
21
    private $value;
22
23
    /**
24
     * Attribute constructor.
25
     *
26
     * @param string      $name
27
     * @param string|null $value
28
     */
29
    public function __construct(string $name, string $value = null)
30 12
    {
31
        $this->name = $name;
32 12
33
        $this->setValue($value ?? '');
34 12
    }
35 12
36
    /**
37 12
     * @return string
38
     */
39
    final public function getName(): string
40
    {
41
        return $this->name;
42 12
    }
43
44 12
    /**
45
     * @param string $value
46
     */
47
    final public function setValue(string $value)
48
    {
49
        $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...
50 9
        if (strlen($value) !== 0) {
51
            $this->value = $value;
52 9
        }
53
    }
54
55
    /**
56
     * @return bool
57
     */
58 12
    final public function hasValue(): bool
59
    {
60 12
        return $this->value !== null;
61 12
    }
62 12
63
    /**
64 12
     * @return string
65
     */
66
    final public function getValue(): string
67
    {
68
        return $this->value;
69 12
    }
70
71 12
    /**
72
     * @param AttributeVisitorInterface $visitor
73
     */
74
    public function accept(AttributeVisitorInterface $visitor)
75
    {
76
        $visitor->visitAttribute($this);
77
    }
78
}