Completed
Push — master ( 5e1312...160e4d )
by Denis
01:45
created

Checkbox::checked()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Ngtfkx\Laradeck\FormBuilder\Elements;
4
5
6
class Checkbox extends AbstractElement
7
{
8
    public $checked = false;
9
10
    public function __construct(?string $name = null, ?string $value = '1', ?bool $state = false)
11
    {
12
        $this->name($name);
13
14
        $this->value($value);
15
16
        $this->checked($state);
17
18
        parent::__construct();
19
    }
20
21
    public function checked(?bool $state = true)
22
    {
23
        $this->checked = $state ?: false;
24
    }
25
26
    public function tag(): void
27
    {
28
        $this->tag = 'input type="checkbox"';
29
    }
30
31
    public function __toString()
32
    {
33
        $this->addAttrAs('checked');
34
35
        return parent::__toString();
36
    }
37
}