Passed
Push — master ( 785275...6b3bd5 )
by Sergei
03:40 queued 29s
created

Field::time()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\YiisoftFormModel;
6
7
use Yiisoft\Form\Field\Button;
8
use Yiisoft\Form\Field\ButtonGroup;
9
use Yiisoft\Form\Field\Checkbox;
10
use Yiisoft\Form\Field\CheckboxList;
11
use Yiisoft\Form\Field\Date;
12
use Yiisoft\Form\Field\DateTime;
13
use Yiisoft\Form\Field\DateTimeLocal;
14
use Yiisoft\Form\Field\Email;
15
use Yiisoft\Form\Field\Time;
16
use Yiisoft\Form\YiisoftFormModel\Field\ErrorSummary;
17
use Yiisoft\Form\Field\Fieldset;
18
use Yiisoft\Form\Field\File;
19
use Yiisoft\Form\Field\Hidden;
20
use Yiisoft\Form\Field\Image;
21
use Yiisoft\Form\Field\Number;
22
use Yiisoft\Form\Field\Part\Error;
23
use Yiisoft\Form\Field\Part\Hint;
24
use Yiisoft\Form\Field\Part\Label;
25
use Yiisoft\Form\Field\Password;
26
use Yiisoft\Form\Field\RadioList;
27
use Yiisoft\Form\Field\Range;
28
use Yiisoft\Form\Field\ResetButton;
29
use Yiisoft\Form\Field\Select;
30
use Yiisoft\Form\Field\SubmitButton;
31
use Yiisoft\Form\Field\Telephone;
32
use Yiisoft\Form\Field\Text;
33
use Yiisoft\Form\Field\Textarea;
34
use Yiisoft\Form\Field\Url;
35
36
class Field
37
{
38
    /**
39
     * @var string|null
40
     */
41
    protected const DEFAULT_THEME = null;
42
43 1
    final public static function button(?string $content = null, array $config = [], ?string $theme = null): Button
44
    {
45 1
        $field = Button::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
46
47 1
        if ($content !== null) {
48 1
            $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 1
        return $field;
52
    }
53
54 1
    final public static function buttonGroup(array $config = [], ?string $theme = null): ButtonGroup
55
    {
56 1
        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 1
    final public static function checkbox(
60
        FormModelInterface $formModel,
61
        string $property,
62
        array $config = [],
63
        ?string $theme = null,
64
    ): Checkbox {
65 1
        return Checkbox::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
66 1
            ->inputData(new FormModelInputData($formModel, $property));
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 FormModelInputData($formModel, $property));
Loading history...
67
    }
68
69 1
    final public static function checkboxList(
70
        FormModelInterface $formModel,
71
        string $property,
72
        array $config = [],
73
        ?string $theme = null,
74
    ): CheckboxList {
75 1
        return CheckboxList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
76 1
            ->inputData(new FormModelInputData($formModel, $property));
77
    }
78
79 1
    final public static function date(
80
        FormModelInterface $formModel,
81
        string $property,
82
        array $config = [],
83
        ?string $theme = null,
84
    ): Date {
85 1
        return Date::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
86 1
            ->inputData(new FormModelInputData($formModel, $property));
87
    }
88
89 1
    final public static function dateTime(
90
        FormModelInterface $formModel,
91
        string $property,
92
        array $config = [],
93
        ?string $theme = null,
94
    ): DateTime {
95 1
        return DateTime::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
96 1
            ->inputData(new FormModelInputData($formModel, $property));
97
    }
98
99 1
    final public static function dateTimeLocal(
100
        FormModelInterface $formModel,
101
        string $property,
102
        array $config = [],
103
        ?string $theme = null,
104
    ): DateTimeLocal {
105 1
        return DateTimeLocal::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
106 1
            ->inputData(new FormModelInputData($formModel, $property));
107
    }
108
109 1
    final public static function email(
110
        FormModelInterface $formModel,
111
        string $property,
112
        array $config = [],
113
        ?string $theme = null,
114
    ): Email {
115 1
        return Email::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
116 1
            ->inputData(new FormModelInputData($formModel, $property));
117
    }
118
119 3
    final public static function errorSummary(
120
        FormModelInterface $formModel,
121
        array $config = [],
122
        ?string $theme = null,
123
    ): ErrorSummary {
124 3
        return ErrorSummary::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
125 3
            ->validationResult($formModel->getValidationResult());
0 ignored issues
show
Bug introduced by
The method validationResult() does not exist on Yiisoft\Widget\Widget. It seems like you code against a sub-type of Yiisoft\Widget\Widget such as Yiisoft\Form\YiisoftFormModel\Field\ErrorSummary. ( Ignorable by Annotation )

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

125
            ->/** @scrutinizer ignore-call */ validationResult($formModel->getValidationResult());
Loading history...
126
    }
127
128 2
    final public static function fieldset(array $config = [], ?string $theme = null): Fieldset
129
    {
130 2
        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...
131
    }
132
133 1
    final public static function file(
134
        FormModelInterface $formModel,
135
        string $property,
136
        array $config = [],
137
        ?string $theme = null,
138
    ): File {
139 1
        return File::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
140 1
            ->inputData(new FormModelInputData($formModel, $property));
141
    }
142
143 2
    final public static function hidden(
144
        FormModelInterface $formModel,
145
        string $property,
146
        array $config = [],
147
        ?string $theme = null,
148
    ): Hidden {
149 2
        return Hidden::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
150 2
            ->inputData(new FormModelInputData($formModel, $property));
151
    }
152
153 1
    final public static function image(array $config = [], ?string $theme = null): Image
154
    {
155 1
        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...
156
    }
157
158 1
    final public static function number(
159
        FormModelInterface $formModel,
160
        string $property,
161
        array $config = [],
162
        ?string $theme = null,
163
    ): Number {
164 1
        return Number::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
165 1
            ->inputData(new FormModelInputData($formModel, $property));
166
    }
167
168 1
    final public static function password(
169
        FormModelInterface $formModel,
170
        string $property,
171
        array $config = [],
172
        ?string $theme = null,
173
    ): Password {
174 1
        return Password::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
175 1
            ->inputData(new FormModelInputData($formModel, $property));
176
    }
177
178 1
    final public static function radioList(
179
        FormModelInterface $formModel,
180
        string $property,
181
        array $config = [],
182
        ?string $theme = null,
183
    ): RadioList {
184 1
        return RadioList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
185 1
            ->inputData(new FormModelInputData($formModel, $property));
186
    }
187
188 1
    final public static function range(
189
        FormModelInterface $formModel,
190
        string $property,
191
        array $config = [],
192
        ?string $theme = null,
193
    ): Range {
194 1
        return Range::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
195 1
            ->inputData(new FormModelInputData($formModel, $property));
196
    }
197
198 1
    final public static function resetButton(
199
        ?string $content = null,
200
        array $config = [],
201
        ?string $theme = null,
202
    ): ResetButton {
203 1
        $field = ResetButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
204
205 1
        if ($content !== null) {
206 1
            $field = $field->content($content);
207
        }
208
209 1
        return $field;
210
    }
211
212 1
    final public static function select(
213
        FormModelInterface $formModel,
214
        string $property,
215
        array $config = [],
216
        ?string $theme = null,
217
    ): Select {
218 1
        return Select::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
219 1
            ->inputData(new FormModelInputData($formModel, $property));
220
    }
221
222 1
    final public static function submitButton(
223
        ?string $content = null,
224
        array $config = [],
225
        ?string $theme = null,
226
    ): SubmitButton {
227 1
        $field = SubmitButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
228
229 1
        if ($content !== null) {
230 1
            $field = $field->content($content);
231
        }
232
233 1
        return $field;
234
    }
235
236 1
    final public static function telephone(
237
        FormModelInterface $formModel,
238
        string $property,
239
        array $config = [],
240
        ?string $theme = null,
241
    ): Telephone {
242 1
        return Telephone::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
243 1
            ->inputData(new FormModelInputData($formModel, $property));
244
    }
245
246 3
    final public static function text(
247
        FormModelInterface $formModel,
248
        string $property,
249
        array $config = [],
250
        ?string $theme = null,
251
    ): Text {
252 3
        return Text::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
253 3
            ->inputData(new FormModelInputData($formModel, $property));
254
    }
255
256 1
    final public static function textarea(
257
        FormModelInterface $formModel,
258
        string $property,
259
        array $config = [],
260
        ?string $theme = null,
261
    ): Textarea {
262 1
        return Textarea::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
263 1
            ->inputData(new FormModelInputData($formModel, $property));
264
    }
265
266 1
    final public static function time(
267
        FormModelInterface $formModel,
268
        string $property,
269
        array $config = [],
270
        ?string $theme = null,
271
    ): Time {
272 1
        return Time::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
273 1
            ->inputData(new FormModelInputData($formModel, $property));
274
    }
275
276 1
    final public static function url(
277
        FormModelInterface $formModel,
278
        string $property,
279
        array $config = [],
280
        ?string $theme = null,
281
    ): Url {
282 1
        return Url::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
283 1
            ->inputData(new FormModelInputData($formModel, $property));
284
    }
285
286 1
    final public static function label(
287
        FormModelInterface $formModel,
288
        string $property,
289
        array $config = [],
290
        ?string $theme = null,
291
    ): Label {
292 1
        return Label::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
293 1
            ->inputData(new FormModelInputData($formModel, $property));
294
    }
295
296 6
    final public static function hint(
297
        FormModelInterface $formModel,
298
        string $property,
299
        array $config = [],
300
        ?string $theme = null,
301
    ): Hint {
302 6
        return Hint::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
303 6
            ->inputData(new FormModelInputData($formModel, $property));
304
    }
305
306 6
    final public static function error(
307
        FormModelInterface $formModel,
308
        string $property,
309
        array $config = [],
310
        ?string $theme = null,
311
    ): Error {
312 6
        return Error::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
313 6
            ->inputData(new FormModelInputData($formModel, $property));
314
    }
315
}
316