Checkbox   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
eloc 14
c 2
b 0
f 1
dl 0
loc 42
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setChecked() 0 4 2
A overwriteValue() 0 4 1
A setSpecificAttributes() 0 4 1
A attributesList() 0 4 1
A setStyles() 0 8 2
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