Passed
Push — master ( a90def...5de986 )
by Chris
04:49
created

Option::isSelected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace WebTheory\Saveyour\Elements;
4
5
use WebTheory\Html\AbstractHtmlElement;
6
7
class Option extends AbstractHtmlElement
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $text;
13
14
    /**
15
     * @var string
16
     */
17
    protected $value;
18
19
    /**
20
     * @var bool
21
     */
22
    protected $selected = false;
23
24
    /**
25
     * @var bool
26
     */
27
    protected $disabled = false;
28
29
    /**
30
     *
31
     */
32
    public function __construct(string $text, string $value)
33
    {
34
        $this->text = $text;
35
        $this->value = $value;
36
37
        parent::__construct();
38
    }
39
40
    /**
41
     * Get the value of text
42
     *
43
     * @return string
44
     */
45
    public function getText(): string
46
    {
47
        return $this->text;
48
    }
49
50
    /**
51
     * Get the value of value
52
     *
53
     * @return mixed
54
     */
55
    public function getValue()
56
    {
57
        return $this->value;
58
    }
59
60
    /**
61
     * Get the value of selected
62
     *
63
     * @return bool
64
     */
65
    public function isSelected(): bool
66
    {
67
        return $this->selected;
68
    }
69
70
    /**
71
     * Set the value of selected
72
     *
73
     * @param bool $selected
74
     *
75
     * @return self
76
     */
77
    public function setSelected(bool $selected)
78
    {
79
        $this->selected = $selected;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Get the value of disabled
86
     *
87
     * @return bool
88
     */
89
    public function isDisabled(): bool
90
    {
91
        return $this->disabled;
92
    }
93
94
    /**
95
     * Set the value of disabled
96
     *
97
     * @param bool $disabled
98
     *
99
     * @return self
100
     */
101
    public function setDisabled(bool $disabled)
102
    {
103
        $this->disabled = $disabled;
104
105
        return $this;
106
    }
107
108
    /**
109
     *
110
     */
111
    protected function resolveAttributes(): AbstractHtmlElement
112
    {
113
        return parent::resolveAttributes()
114
            ->addAttribute('value', $this->value)
0 ignored issues
show
Bug introduced by
'value' of type string is incompatible with the type array expected by parameter $attribute of WebTheory\Html\AbstractHtmlElement::addAttribute(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

114
            ->addAttribute(/** @scrutinizer ignore-type */ 'value', $this->value)
Loading history...
115
            ->addAttribute('selected', $this->selected)
116
            ->addAttribute('disabled', $this->disabled);
117
    }
118
119
    /**
120
     *
121
     */
122
    protected function renderHtmlMarkup(): string
123
    {
124
        return $this->tag('option', $this->text, $this->attributes);
125
    }
126
}
127