Completed
Push — master ( d2f848...b4f8f5 )
by Denis
07:12
created

Form   B

Complexity

Total Complexity 11

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 7
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 155
rs 8.3333
c 0
b 0
f 0
wmc 11
lcom 7
cbo 1

11 Methods

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