OptGroup::resolveAttributes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 5
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\Saveyour\Field\Abstracts\AbstractValuableElement;
6
use WebTheory\Saveyour\Field\Abstracts\MultiValueSelectionTrait;
7
use WebTheory\Saveyour\Field\Abstracts\RendersOptionsTrait;
8
9
class OptGroup extends AbstractValuableElement
10
{
11
    use MultiValueSelectionTrait;
12
    use RendersOptionsTrait;
13
14
    protected $value = [];
15
16
    protected string $label;
17
18
    protected bool $disabled = false;
19
20
    public function __construct(string $label)
21
    {
22
        $this->label = $label;
23
24
        parent::__construct();
25
    }
26
27
    public function isDisabled(): bool
28
    {
29
        return $this->disabled;
30
    }
31
32
    /**
33
     * @return $this
34
     */
35
    public function setDisabled(bool $disabled): OptGroup
36
    {
37
        $this->disabled = $disabled;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @return $this
44
     */
45
    protected function resolveAttributes(): OptGroup
46
    {
47
        parent::resolveAttributes()
48
            ->addAttribute('label', $this->label)
49
            ->addAttribute('disabled', $this->disabled);
50
51
        return $this;
52
    }
53
54
    protected function renderHtmlMarkup(): string
55
    {
56
        return $this->tag('optgroup', $this->attributes, $this->renderSelection());
57
    }
58
}
59