Passed
Push — master ( 6b3bd5...b249fa )
by Sergei
05:31 queued 02:48
created

PureField   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 269
Duplicated Lines 0 %

Test Coverage

Coverage 10.71%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 59
c 2
b 0
f 0
dl 0
loc 269
ccs 9
cts 84
cp 0.1071
rs 10
wmc 30

27 Methods

Rating   Name   Duplication   Size   Complexity  
A buttonGroup() 0 3 1
A button() 0 9 2
A textarea() 0 8 1
A hint() 0 8 1
A url() 0 8 1
A checkbox() 0 8 1
A fieldset() 0 3 1
A label() 0 8 1
A submitButton() 0 12 2
A password() 0 8 1
A dateTime() 0 8 1
A radioList() 0 8 1
A checkboxList() 0 8 1
A date() 0 8 1
A image() 0 3 1
A telephone() 0 8 1
A number() 0 8 1
A resetButton() 0 12 2
A select() 0 8 1
A file() 0 8 1
A error() 0 8 1
A dateTimeLocal() 0 8 1
A range() 0 8 1
A time() 0 8 1
A email() 0 8 1
A text() 0 8 1
A hidden() 0 8 1
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\Time;
34
use Yiisoft\Form\Field\Url;
35
36
class PureField
37
{
38
    /**
39
     * @var string|null
40
     */
41
    protected const DEFAULT_THEME = null;
42
43
    final public static function button(?string $content = null, array $config = [], ?string $theme = null): Button
44
    {
45
        $field = Button::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
46
47
        if ($content !== null) {
48
            $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

48
            /** @scrutinizer ignore-call */ 
49
            $field = $field->content($content);
Loading history...
49
        }
50
51
        return $field;
52
    }
53
54
    final public static function buttonGroup(array $config = [], ?string $theme = null): ButtonGroup
55
    {
56
        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...
57
    }
58
59
    final public static function checkbox(
60
        ?string $name = null,
61
        mixed $value = null,
62
        array $config = [],
63
        ?string $theme = null,
64
    ): Checkbox {
65
        return Checkbox::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
66
            ->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

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