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

OptGroup   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 75
ccs 0
cts 23
cp 0
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isDisabled() 0 3 1
A resolveAttributes() 0 5 1
A renderHtmlMarkup() 0 3 1
A __construct() 0 5 1
A setDisabled() 0 5 1
1
<?php
2
3
namespace WebTheory\Saveyour\Elements;
4
5
use WebTheory\Html\AbstractHtmlElement;
6
use WebTheory\Saveyour\Concerns\MultiValueSelectionTrait;
7
use WebTheory\Saveyour\Concerns\RendersOptionsTrait;
8
use WebTheory\Saveyour\Contracts\OptionsProviderInterface;
9
10
class OptGroup extends AbstractHtmlElement
11
{
12
    use MultiValueSelectionTrait;
13
    use RendersOptionsTrait;
14
15
    /**
16
     *
17
     */
18
    protected $value = [];
19
20
    /**
21
     * @var string
22
     */
23
    protected $label;
24
25
    /**
26
     * @var bool
27
     */
28
    protected $disabled = false;
29
30
    /**
31
     * @var OptionsProviderInterface
32
     */
33
    protected $selectionProvider;
34
35
    /**
36
     *
37
     */
38
    public function __construct(string $label)
39
    {
40
        $this->label = $label;
41
42
        parent::__construct();
43
    }
44
45
    /**
46
     * Get the value of disabled
47
     *
48
     * @return bool
49
     */
50
    public function isDisabled(): bool
51
    {
52
        return $this->disabled;
53
    }
54
55
    /**
56
     * Set the value of disabled
57
     *
58
     * @param bool $disabled
59
     *
60
     * @return self
61
     */
62
    public function setDisabled(bool $disabled)
63
    {
64
        $this->disabled = $disabled;
65
66
        return $this;
67
    }
68
69
    /**
70
     *
71
     */
72
    protected function resolveAttributes(): AbstractHtmlElement
73
    {
74
        return parent::resolveAttributes()
75
            ->addAttribute('label', $this->label)
0 ignored issues
show
Bug introduced by
'label' 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

75
            ->addAttribute(/** @scrutinizer ignore-type */ 'label', $this->label)
Loading history...
76
            ->addAttribute('disabled', $this->disabled);
77
    }
78
79
    /**
80
     *
81
     */
82
    protected function renderHtmlMarkup(): string
83
    {
84
        return $this->tag('optgroup', $this->renderSelection(), $this->attributes);
85
    }
86
}
87