Option::getValue()   A
last analyzed

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