Form   B
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 172
Duplicated Lines 0 %

Coupling/Cohesion

Components 7
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 172
rs 8.3333
c 0
b 0
f 0
wmc 13
lcom 7
cbo 2

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A action() 0 6 1
A method() 0 6 1
A enctype() 0 6 1
A target() 0 6 1
A multipart() 0 4 1
A plain() 0 4 1
A urlencoded() 0 4 1
A autocomplete() 0 6 1
A novalidate() 0 6 1
A tag() 0 4 1
A __toString() 0 17 2
1
<?php
2
3
namespace Ngtfkx\Laradeck\FormBuilder\Elements;
4
5
6
use Ngtfkx\Laradeck\FormBuilder\Providers\AbstractProvider;
7
8
class Form extends AbstractElement
9
{
10
    /**
11
     * @var string URL для отправки данных формы
12
     */
13
    protected $action = '';
14
15
    /**
16
     * @var string Метод отправки данных формы
17
     */
18
    protected $method = 'get';
19
20
    /**
21
     * @var bool Признак включения/отключения автозаполнения полей формы
22
     */
23
    protected $autocomplete;
24
25
    /**
26
     * @var bool Признак включения/откючения автовалидации перед отправкой данных
27
     */
28
    protected $novalidate;
29
30
    /**
31
     * @var string В каком окне открывать результат обработки формы
32
     */
33
    protected $target;
34
35
    /**
36
     * @var string Тип кодировки данных при отправке
37
     */
38
    protected $enctype;
39
40
    public $onlyTagRender = true;
41
42
    /**
43
     * Form constructor.
44
     * @param AbstractProvider $layout
45
     */
46
    public function __construct(?AbstractProvider $layout = null)
47
    {
48
        parent::__construct();
49
50
        $this->layout = $layout;
51
    }
52
53
    /**
54
     * @param string|null $value
55
     * @return Form
56
     */
57
    public function action(?string $value = ''): Form
58
    {
59
        $this->action = $value;
60
61
        return $this;
62
    }
63
64
    /**
65
     * @param string|null  $value
66
     * @return Form
67
     */
68
    public function method(?string $value): Form
69
    {
70
        $this->method = $value;
71
72
        return $this;
73
    }
74
75
    /**
76
     * Сеттер для установки типа кодировки данных при отправке
77
     *
78
     * @param string $value
79
     * @return Form
80
     */
81
    protected function enctype(string $value): Form
82
    {
83
        $this->enctype = $value;
84
85
        return $this;
86
    }
87
88
    /**
89
     * Сеттер для установки указания в каком окнеоткрывать результат работы
90
     *
91
     * @param string|null $value
92
     * @return Form
93
     */
94
    public function target(?string $value): Form
95
    {
96
        $this->target = $value;
97
98
        return $this;
99
    }
100
101
    /**
102
     * Установить тип отправки данных multipart/form-data
103
     *
104
     * @return Form
105
     */
106
    public function multipart(): Form
107
    {
108
        return $this->enctype('multipart/form-data');
109
    }
110
111
    /**
112
     * Установить тип отправки данных text/plain
113
     *
114
     * @return Form
115
     */
116
    public function plain(): Form
117
    {
118
        return $this->enctype('text/plain');
119
    }
120
121
    /**
122
     * Установить тип отправки данных application/x-www-form-urlencoded
123
     *
124
     * @return Form
125
     */
126
    public function urlencoded(): Form
127
    {
128
        return $this->enctype('application/x-www-form-urlencoded');
129
    }
130
131
    /**
132
     * Сеттер для установки признака включения/отключения автозаполнения полей формы
133
     *
134
     * @param bool|null $state
135
     * @return Form
136
     */
137
    public function autocomplete(?bool $state = true): Form
138
    {
139
        $this->autocomplete = $state;
140
141
        return $this;
142
    }
143
144
    /**
145
     * Сеттер для установки признака включения/отключения автовалидации перед отправкой данных
146
     *
147
     * @param bool|null $state
148
     * @return Form
149
     */
150
    public function novalidate(?bool $state = true): Form
151
    {
152
        $this->novalidate = $state;
153
154
        return $this;
155
    }
156
157
    public function tag(): void
158
    {
159
        $this->tag = 'form';
160
    }
161
162
    public function __toString(): string
163
    {
164
        if ($this->layout) {
165
            $this->class($this->layout->getFormClasses());
166
        }
167
168
        $this->attrs([
0 ignored issues
show
Documentation introduced by
array('action' => $this-...' => $this->novalidate) is of type array<string,string|bool...novalidate":"boolean"}>, but the function expects a object<Ngtfkx\Laradeck\F...lder\Elements\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
169
                'action' => $this->action,
170
                'method' => $this->method,
171
                'target' => $this->target,
172
                'enctype' => $this->enctype,
173
                'autocomplete' => $this->autocomplete,
174
                'novalidate' => $this->novalidate,
175
            ]);
176
177
        return parent::__toString();
178
    }
179
}