Checkbox::setStyles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace SoareCostin\BladeFormComponents\FormElements;
4
5
use SoareCostin\BladeFormComponents\FormElement;
6
7
class Checkbox extends FormElement
8
{
9
    /** @var string */
10
    public $type = 'checkbox';
11
12
    /** @var bool */
13
    public $checked = false;
14
15
    protected function attributesList()
16
    {
17
        return [
18
            'id', 'name', 'type', 'value', 'class', 'checked', 'required', 'disabled', 'readonly', 'autocomplete',
19
        ];
20
    }
21
22
    protected function setSpecificAttributes()
23
    {
24
        $this->setChecked();
25
        $this->overwriteValue();
26
    }
27
28
    protected function setChecked()
29
    {
30
        if ($this->value) {
31
            $this->checked = true;
32
        }
33
    }
34
35
    protected function overwriteValue()
36
    {
37
        // Overwrite the value to 1
38
        $this->value = 1;
39
    }
40
41
    protected function setStyles()
42
    {
43
        $this->class[] = config('blade-form-components.themes.'.$this->getTheme().'.fields.checkbox') ?? config('blade-form-components.themes.'.$this->getTheme().'.fields.default');
44
        $this->labelClass[] = config('blade-form-components.themes.'.$this->getTheme().'.labels.checkbox');
45
46
        // Attach the error class if an error is displayed against this field
47
        if ($this->form->errors->has($this->name)) {
48
            $this->labelClass[] = config('blade-form-components.themes.'.$this->getTheme().'.fields.is-error');
49
        }
50
    }
51
}
52