Option::selected()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Html\Elements;
4
5
use Spatie\Html\Selectable;
6
use Spatie\Html\BaseElement;
7
8
class Option extends BaseElement implements Selectable
9
{
10
    /** @var string */
11
    protected $tag = 'option';
12
13
    /**
14
     * @return static
15
     */
16
    public function selected()
17
    {
18
        return $this->attribute('selected', 'selected');
19
    }
20
21
    /**
22
     * @param bool $condition
23
     *
24
     * @return static
25
     */
26
    public function selectedIf($condition)
27
    {
28
        return $condition ?
29
            $this->selected() :
30
            $this->unselected();
31
    }
32
33
    /**
34
     * @return static
35
     */
36
    public function unselected()
37
    {
38
        return $this->forgetAttribute('selected');
39
    }
40
41
    /**
42
     * @param string|null $value
43
     *
44
     * @return static
45
     */
46
    public function value($value)
47
    {
48
        return $this->attribute('value', $value);
49
    }
50
}
51