Passed
Push — main ( 47a406...6037b2 )
by Thierry
02:35
created

FormBuilderTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 86
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A label() 0 3 1
A inputGroup() 0 3 1
A radio() 0 3 1
A form() 0 3 1
A option() 0 3 1
A checkbox() 0 3 1
1
<?php
2
3
namespace Lagdo\UiBuilder\Builder;
4
5
use Lagdo\UiBuilder\Component\CheckboxComponent;
6
use Lagdo\UiBuilder\Component\FormComponent;
7
use Lagdo\UiBuilder\Component\InputGroupComponent;
8
use Lagdo\UiBuilder\Component\LabelComponent;
9
use Lagdo\UiBuilder\Component\OptionComponent;
10
use Lagdo\UiBuilder\Component\RadioComponent;
11
use Lagdo\UiBuilder\Component\Base\HtmlComponent;
12
13
trait FormBuilderTrait
14
{
15
    /**
16
     * @return string
17
     */
18
    abstract protected function _formComponentClass(): string;
19
20
    /**
21
     * @return string
22
     */
23
    abstract protected function _labelComponentClass(): string;
24
25
    /**
26
     * @return string
27
     */
28
    abstract protected function _inputGroupComponentClass(): string;
29
30
    /**
31
     * @return string
32
     */
33
    abstract protected function _checkboxComponentClass(): string;
34
35
    /**
36
     * @return string
37
     */
38
    abstract protected function _radioComponentClass(): string;
39
40
    /**
41
     * @return string
42
     */
43
    abstract protected function _optionComponentClass(): string;
44
45
    /**
46
     * @param string $tagName
47
     * @param array $arguments
48
     *
49
     * @return HtmlComponent
50
     */
51
    abstract protected function createFormComponent(string $tagName, $arguments): HtmlComponent;
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public function form(...$arguments): FormComponent
57
    {
58
        return $this->createComponentOfClass($this->_formComponentClass(), $arguments);
0 ignored issues
show
Bug introduced by
It seems like createComponentOfClass() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        return $this->/** @scrutinizer ignore-call */ createComponentOfClass($this->_formComponentClass(), $arguments);
Loading history...
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function label(...$arguments): LabelComponent
65
    {
66
        return $this->createComponentOfClass($this->_labelComponentClass(), $arguments);
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function inputGroup(...$arguments): InputGroupComponent
73
    {
74
        return $this->createComponentOfClass($this->_inputGroupComponentClass(), $arguments);
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80
    public function checkbox(...$arguments): CheckboxComponent
81
    {
82
        return $this->createComponentOfClass($this->_checkboxComponentClass(), $arguments);
83
    }
84
85
    /**
86
     * @inheritDoc
87
     */
88
    public function radio(...$arguments): RadioComponent
89
    {
90
        return $this->createComponentOfClass($this->_radioComponentClass(), $arguments);
91
    }
92
93
    /**
94
     * @inheritDoc
95
     */
96
    public function option(...$arguments): OptionComponent
97
    {
98
        return $this->createComponentOfClass($this->_optionComponentClass(), $arguments);
99
    }
100
}
101