Form   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decorateCheckboxGroup() 0 6 1
A init() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\PropellerAdmin\Decorator;
6
7
use AbterPhp\Framework\Constant\Html5;
8
use AbterPhp\Framework\Decorator\Decorator;
9
use AbterPhp\Framework\Decorator\Rule;
10
use AbterPhp\Framework\Form\Container\FormGroup;
11
use AbterPhp\Framework\Form\Container\CheckboxGroup;
12
use AbterPhp\Framework\Form\Element\Input;
13
use AbterPhp\Framework\Form\Element\Select;
14
use AbterPhp\Framework\Form\Element\Textarea;
15
use AbterPhp\Framework\Form\Extra\DefaultButtons;
16
use AbterPhp\Framework\Form\Label\Label;
17
use AbterPhp\Framework\Html\Component\Button;
18
19
class Form extends Decorator
20
{
21
    const DEFAULT_FORM_GROUP_CLASS = 'form-group';
22
    const DEFAULT_LABEL_CLASS      = 'control-label';
23
    const DEFAULT_INPUT_CLASS      = 'form-control';
24
    const DEFAULT_BUTTONS_CLASS    = 'form-group pmd-textfield pmd-textfield-floating-label';
25
    const DEFAULT_BUTTON_CLASS     = 'pmd-checkbox-ripple-effect';
26
27
    const CHECKBOX_GROUP_CLASS = 'checkbox pmd-default-theme';
28
    const CHECKBOX_LABEL_CLASS = 'pmd-checkbox pmd-checkbox-ripple-effect';
29
30
    /**
31
     * @return Decorator
32
     */
33
    public function init(): Decorator
34
    {
35
        // Add the appropriate class to form labels
36
        $this->rules[] = new Rule([], Label::class, [static::DEFAULT_LABEL_CLASS]);
37
38
        // Add the appropriate class to form labels
39
        $this->rules[] = new Rule([], Input::class, [static::DEFAULT_INPUT_CLASS]);
40
        $this->rules[] = new Rule([], Textarea::class, [static::DEFAULT_INPUT_CLASS]);
41
        $this->rules[] = new Rule([], Select::class, [static::DEFAULT_INPUT_CLASS]);
42
        $this->rules[] = new Rule([], FormGroup::class, [static::DEFAULT_FORM_GROUP_CLASS]);
43
        $this->rules[] = new Rule([], DefaultButtons::class, [static::DEFAULT_BUTTONS_CLASS]);
44
        $this->rules[] = new Rule([Button::INTENT_FORM], Button::class, [static::DEFAULT_BUTTON_CLASS]);
45
        $this->rules[] = new Rule([], CheckboxGroup::class, [], [], [$this, 'decorateCheckboxGroup']);
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param CheckboxGroup $checkboxGroup
52
     */
53
    public function decorateCheckboxGroup(CheckboxGroup $checkboxGroup)
54
    {
55
        $checkboxGroup->setAttribute(Html5::ATTR_CLASS, static::CHECKBOX_GROUP_CLASS);
56
57
        $checkboxGroup->getLabel()->setAttribute(Html5::ATTR_CLASS, static::CHECKBOX_LABEL_CLASS);
58
        $checkboxGroup->getInput()->unsetAttribute(Html5::ATTR_CLASS);
59
    }
60
}
61