Completed
Push — master ( 5e1312...160e4d )
by Denis
01:45
created

Form::method()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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 = true;
22
23
    /**
24
     * @var bool Признак включения/откючения автовалидации перед отправкой данных
25
     */
26
    protected $novalidate = false;
27
28
    /**
29
     * @var string В каком окне открывать результат обработки формы
30
     */
31
    protected $target = '_self';
32
33
    /**
34
     * @var string Тип кодировки данных при отправке
35
     */
36
    protected $enctype = 'application/x-www-form-urlencoded';
37
38
    /**
39
     * @param string $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 $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
     * Установить тип отправки данных multipart/form-data
75
     *
76
     * @return Form
77
     */
78
    public function multipart(): Form
79
    {
80
        return $this->enctype('multipart/form-data');
81
    }
82
83
    /**
84
     * Установить тип отправки данных text/plain
85
     *
86
     * @return Form
87
     */
88
    public function plain(): Form
89
    {
90
        return $this->enctype('text/plain');
91
    }
92
93
    /**
94
     * Установить тип отправки данных application/x-www-form-urlencoded
95
     *
96
     * @return Form
97
     */
98
    public function urlencoded(): Form
99
    {
100
        return $this->enctype('application/x-www-form-urlencoded');
101
    }
102
103
    /**
104
     * Сеттер для установки признака включения/отключения автозаполнения полей формы
105
     *
106
     * @param bool $state
107
     * @return Form
108
     */
109
    public function autocomplete(bool $state = true): Form
110
    {
111
        $this->autocomplete = $state;
112
113
        return $this;
114
    }
115
116
    /**
117
     * Сеттер для установки признака включения/отключения автовалидации перед отправкой данных
118
     *
119
     * @param bool $state
120
     * @return Form
121
     */
122
    public function novalidate(bool $state = true): Form
123
    {
124
        $this->novalidate = $state;
125
126
        return $this;
127
    }
128
129
    public function tag(): void
130
    {
131
        $this->tag = 'form';
132
    }
133
134
    public function __toString()
135
    {
136
        $this->id($this->id)
137
            ->name($this->name)
138
            ->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...
139
                'action' => $this->action,
140
                'method' => $this->method,
141
                'enctype' => $this->enctype,
142
                'autocomplete' => $this->autocomplete,
143
                'novalidate' => $this->novalidate,
144
            ]);
145
146
        return parent::__toString();
147
    }
148
}