Passed
Pull Request — master (#284)
by Sergei
02:54
created

Field::checkboxList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form;
6
7
use Yiisoft\Form\Field\Base\InputData\PureInputData;
8
use Yiisoft\Form\Field\Button;
9
use Yiisoft\Form\Field\ButtonGroup;
10
use Yiisoft\Form\Field\Checkbox;
11
use Yiisoft\Form\Field\CheckboxList;
12
use Yiisoft\Form\Field\Date;
13
use Yiisoft\Form\Field\DateTime;
14
use Yiisoft\Form\Field\DateTimeLocal;
15
use Yiisoft\Form\Field\Email;
16
use Yiisoft\Form\Field\Fieldset;
17
use Yiisoft\Form\Field\File;
18
use Yiisoft\Form\Field\Hidden;
19
use Yiisoft\Form\Field\Image;
20
use Yiisoft\Form\Field\Number;
21
use Yiisoft\Form\Field\Part\Error;
22
use Yiisoft\Form\Field\Part\Hint;
23
use Yiisoft\Form\Field\Part\Label;
24
use Yiisoft\Form\Field\Password;
25
use Yiisoft\Form\Field\RadioList;
26
use Yiisoft\Form\Field\Range;
27
use Yiisoft\Form\Field\ResetButton;
28
use Yiisoft\Form\Field\Select;
29
use Yiisoft\Form\Field\SubmitButton;
30
use Yiisoft\Form\Field\Telephone;
31
use Yiisoft\Form\Field\Text;
32
use Yiisoft\Form\Field\Textarea;
33
use Yiisoft\Form\Field\Url;
34
35
class Field
36
{
37
    /**
38
     * @var string|null
39
     */
40
    protected const DEFAULT_THEME = null;
41
42
    final public static function button(?string $content = null, array $config = [], ?string $theme = null): Button
43
    {
44
        $field = Button::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
45
46
        if ($content !== null) {
47
            $field = $field->content($content);
0 ignored issues
show
Bug introduced by
The method content() does not exist on Yiisoft\Widget\Widget. It seems like you code against a sub-type of Yiisoft\Widget\Widget such as Yiisoft\Form\Field\Part\Label or Yiisoft\Form\Field\Part\Hint or Yiisoft\Form\Field\Fieldset or Yiisoft\Form\Field\Base\ButtonField. ( Ignorable by Annotation )

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

47
            /** @scrutinizer ignore-call */ 
48
            $field = $field->content($content);
Loading history...
48
        }
49
50
        return $field;
51
    }
52
53
    final public static function buttonGroup(array $config = [], ?string $theme = null): ButtonGroup
54
    {
55
        return ButtonGroup::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Yiisoft\Form\Fiel... static::DEFAULT_THEME) returns the type Yiisoft\Widget\Widget which includes types incompatible with the type-hinted return Yiisoft\Form\Field\ButtonGroup.
Loading history...
56
    }
57
58
    final public static function checkbox(
59
        ?string $name = null,
60
        mixed $value = null,
61
        array $config = [],
62
        ?string $theme = null,
63
    ): Checkbox {
64
        return Checkbox::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
65
            ->inputData(new PureInputData($name, $value));
0 ignored issues
show
Bug introduced by
The method inputData() does not exist on Yiisoft\Widget\Widget. It seems like you code against a sub-type of Yiisoft\Widget\Widget such as Yiisoft\Form\Field\Part\Label or Yiisoft\Form\Field\Part\Error or Yiisoft\Form\Field\Part\Hint or Yiisoft\Form\Field\RadioList or Yiisoft\Form\Field\Base\InputField or Yiisoft\Form\Field\CheckboxList. ( Ignorable by Annotation )

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

65
            ->/** @scrutinizer ignore-call */ inputData(new PureInputData($name, $value));
Loading history...
66
    }
67
68
    final public static function checkboxList(
69
        ?string $name = null,
70
        mixed $value = null,
71
        array $config = [],
72
        ?string $theme = null,
73
    ): CheckboxList {
74
        return CheckboxList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
75
            ->inputData(new PureInputData($name, $value));
76
    }
77
78
    final public static function date(
79
        ?string $name = null,
80
        mixed $value = null,
81
        array $config = [],
82
        ?string $theme = null,
83
    ): Date {
84
        return Date::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
85
            ->inputData(new PureInputData($name, $value));
86
    }
87
88
    final public static function dateTime(
89
        ?string $name = null,
90
        mixed $value = null,
91
        array $config = [],
92
        ?string $theme = null,
93
    ): DateTime {
94
        return DateTime::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
95
            ->inputData(new PureInputData($name, $value));
96
    }
97
98
    final public static function dateTimeLocal(
99
        ?string $name = null,
100
        mixed $value = null,
101
        array $config = [],
102
        ?string $theme = null,
103
    ): DateTimeLocal {
104
        return DateTimeLocal::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
105
            ->inputData(new PureInputData($name, $value));
106
    }
107
108
    final public static function email(
109
        ?string $name = null,
110
        mixed $value = null,
111
        array $config = [],
112
        ?string $theme = null,
113
    ): Email {
114
        return Email::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
115
            ->inputData(new PureInputData($name, $value));
116
    }
117
118
    final public static function fieldset(array $config = [], ?string $theme = null): Fieldset
119
    {
120
        return Fieldset::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Yiisoft\Form\Fiel... static::DEFAULT_THEME) returns the type Yiisoft\Widget\Widget which includes types incompatible with the type-hinted return Yiisoft\Form\Field\Fieldset.
Loading history...
121
    }
122
123
    final public static function file(
124
        ?string $name = null,
125
        mixed $value = null,
126
        array $config = [],
127
        ?string $theme = null,
128
    ): File {
129
        return File::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
130
            ->inputData(new PureInputData($name, $value));
131
    }
132
133
    final public static function hidden(
134
        ?string $name = null,
135
        mixed $value = null,
136
        array $config = [],
137
        ?string $theme = null,
138
    ): Hidden {
139
        return Hidden::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
140
            ->inputData(new PureInputData($name, $value));
141
    }
142
143
    final public static function image(array $config = [], ?string $theme = null): Image
144
    {
145
        return Image::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Yiisoft\Form\Fiel... static::DEFAULT_THEME) returns the type Yiisoft\Widget\Widget which includes types incompatible with the type-hinted return Yiisoft\Form\Field\Image.
Loading history...
146
    }
147
148
    final public static function number(
149
        ?string $name = null,
150
        mixed $value = null,
151
        array $config = [],
152
        ?string $theme = null,
153
    ): Number {
154
        return Number::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
155
            ->inputData(new PureInputData($name, $value));
156
    }
157
158
    final public static function password(
159
        ?string $name = null,
160
        mixed $value = null,
161
        array $config = [],
162
        ?string $theme = null,
163
    ): Password {
164
        return Password::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
165
            ->inputData(new PureInputData($name, $value));
166
    }
167
168
    final public static function radioList(
169
        ?string $name = null,
170
        mixed $value = null,
171
        array $config = [],
172
        ?string $theme = null,
173
    ): RadioList {
174
        return RadioList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
175
            ->inputData(new PureInputData($name, $value));
176
    }
177
178
    final public static function range(
179
        ?string $name = null,
180
        mixed $value = null,
181
        array $config = [],
182
        ?string $theme = null,
183
    ): Range {
184
        return Range::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
185
            ->inputData(new PureInputData($name, $value));
186
    }
187
188
    final public static function resetButton(
189
        ?string $content = null,
190
        array $config = [],
191
        ?string $theme = null,
192
    ): ResetButton {
193
        $field = ResetButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
194
195
        if ($content !== null) {
196
            $field = $field->content($content);
197
        }
198
199
        return $field;
200
    }
201
202
    final public static function select(
203
        ?string $name = null,
204
        mixed $value = null,
205
        array $config = [],
206
        ?string $theme = null,
207
    ): Select {
208
        return Select::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
209
            ->inputData(new PureInputData($name, $value));
210
    }
211
212
    final public static function submitButton(
213
        ?string $content = null,
214
        array $config = [],
215
        ?string $theme = null,
216
    ): SubmitButton {
217
        $field = SubmitButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
218
219
        if ($content !== null) {
220
            $field = $field->content($content);
221
        }
222
223
        return $field;
224
    }
225
226
    final public static function telephone(
227
        ?string $name = null,
228
        mixed $value = null,
229
        array $config = [],
230
        ?string $theme = null,
231
    ): Telephone {
232
        return Telephone::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
233
            ->inputData(new PureInputData($name, $value));
234
    }
235
236
    final public static function text(
237
        ?string $name = null,
238
        mixed $value = null,
239
        array $config = [],
240
        ?string $theme = null,
241
    ): Text {
242
        return Text::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
243
            ->inputData(new PureInputData($name, $value));
244
    }
245
246
    final public static function textarea(
247
        ?string $name = null,
248
        mixed $value = null,
249
        array $config = [],
250
        ?string $theme = null,
251
    ): Textarea {
252
        return Textarea::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
253
            ->inputData(new PureInputData($name, $value));
254
    }
255
256
    final public static function url(
257
        ?string $name = null,
258
        mixed $value = null,
259
        array $config = [],
260
        ?string $theme = null,
261
    ): Url {
262
        return Url::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
263
            ->inputData(new PureInputData($name, $value));
264
    }
265
266
    final public static function label(
267
        ?string $name = null,
268
        mixed $value = null,
269
        array $config = [],
270
        ?string $theme = null,
271
    ): Label {
272
        return Label::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
273
            ->inputData(new PureInputData($name, $value));
274
    }
275
276
    final public static function hint(
277
        ?string $name = null,
278
        mixed $value = null,
279
        array $config = [],
280
        ?string $theme = null,
281
    ): Hint {
282
        return Hint::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
283
            ->inputData(new PureInputData($name, $value));
284
    }
285
286
    final public static function error(
287
        ?string $name = null,
288
        mixed $value = null,
289
        array $config = [],
290
        ?string $theme = null,
291
    ): Error {
292
        return Error::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
293
            ->inputData(new PureInputData($name, $value));
294
    }
295
}
296