Passed
Push — master ( 4cf43a...e3fb92 )
by Sergei
03:07
created

PureFieldFactory::dateTime()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 1
rs 10
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\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\Time;
35
use Yiisoft\Form\Field\Url;
36
37
/**
38
 * @psalm-import-type Errors from ErrorSummary
39
 */
40
class PureFieldFactory
41
{
42 63
    final public function __construct(
43
        protected readonly ?string $defaultTheme = null,
44
    ) {
45 63
    }
46
47 3
    final public function button(?string $content = null, array $config = [], ?string $theme = null): Button
48
    {
49 3
        $field = Button::widget(config: $config, theme: $theme ?? $this->defaultTheme);
50
51 3
        if ($content !== null) {
52 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

52
            /** @scrutinizer ignore-call */ 
53
            $field = $field->content($content);
Loading history...
53
        }
54
55 3
        return $field;
56
    }
57
58 2
    final public function buttonGroup(array $config = [], ?string $theme = null): ButtonGroup
59
    {
60 2
        return ButtonGroup::widget(config: $config, theme: $theme ?? $this->defaultTheme);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Yiisoft\Form\Fiel...?? $this->defaultTheme) returns the type Yiisoft\Widget\Widget which includes types incompatible with the type-hinted return Yiisoft\Form\Field\ButtonGroup.
Loading history...
61
    }
62
63 2
    final public function checkbox(
64
        ?string $name = null,
65
        mixed $value = null,
66
        array $config = [],
67
        ?string $theme = null,
68
    ): Checkbox {
69 2
        return Checkbox::widget(config: $config, theme: $theme ?? $this->defaultTheme)
70 2
            ->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

70
            ->/** @scrutinizer ignore-call */ inputData(new PureInputData($name, $value));
Loading history...
71
    }
72
73 2
    final public function checkboxList(
74
        ?string $name = null,
75
        mixed $value = null,
76
        array $config = [],
77
        ?string $theme = null,
78
    ): CheckboxList {
79 2
        return CheckboxList::widget(config: $config, theme: $theme ?? $this->defaultTheme)
80 2
            ->inputData(new PureInputData($name, $value));
81
    }
82
83 2
    final public function date(
84
        ?string $name = null,
85
        mixed $value = null,
86
        array $config = [],
87
        ?string $theme = null,
88
    ): Date {
89 2
        return Date::widget(config: $config, theme: $theme ?? $this->defaultTheme)
90 2
            ->inputData(new PureInputData($name, $value));
91
    }
92
93 2
    final public function dateTime(
94
        ?string $name = null,
95
        mixed $value = null,
96
        array $config = [],
97
        ?string $theme = null,
98
    ): DateTime {
99 2
        return DateTime::widget(config: $config, theme: $theme ?? $this->defaultTheme)
100 2
            ->inputData(new PureInputData($name, $value));
101
    }
102
103 2
    final public function dateTimeLocal(
104
        ?string $name = null,
105
        mixed $value = null,
106
        array $config = [],
107
        ?string $theme = null,
108
    ): DateTimeLocal {
109 2
        return DateTimeLocal::widget(config: $config, theme: $theme ?? $this->defaultTheme)
110 2
            ->inputData(new PureInputData($name, $value));
111
    }
112
113 2
    final public function email(
114
        ?string $name = null,
115
        mixed $value = null,
116
        array $config = [],
117
        ?string $theme = null,
118
    ): Email {
119 2
        return Email::widget(config: $config, theme: $theme ?? $this->defaultTheme)
120 2
            ->inputData(new PureInputData($name, $value));
121
    }
122
123
    /**
124
     * @psalm-param Errors $errors
125
     */
126 2
    final public function errorSummary(
127
        array $errors = [],
128
        array $config = [],
129
        ?string $theme = null,
130
    ): ErrorSummary {
131 2
        return ErrorSummary::widget(config: $config, theme: $theme ?? $this->defaultTheme)->errors($errors);
0 ignored issues
show
Bug introduced by
The method errors() 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\ErrorSummary. ( Ignorable by Annotation )

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

131
        return ErrorSummary::widget(config: $config, theme: $theme ?? $this->defaultTheme)->/** @scrutinizer ignore-call */ errors($errors);
Loading history...
132
    }
133
134 2
    final public function fieldset(array $config = [], ?string $theme = null): Fieldset
135
    {
136 2
        return Fieldset::widget(config: $config, theme: $theme ?? $this->defaultTheme);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Yiisoft\Form\Fiel...?? $this->defaultTheme) returns the type Yiisoft\Widget\Widget which includes types incompatible with the type-hinted return Yiisoft\Form\Field\Fieldset.
Loading history...
137
    }
138
139 2
    final public function file(
140
        ?string $name = null,
141
        mixed $value = null,
142
        array $config = [],
143
        ?string $theme = null,
144
    ): File {
145 2
        return File::widget(config: $config, theme: $theme ?? $this->defaultTheme)
146 2
            ->inputData(new PureInputData($name, $value));
147
    }
148
149 2
    final public function hidden(
150
        ?string $name = null,
151
        mixed $value = null,
152
        array $config = [],
153
        ?string $theme = null,
154
    ): Hidden {
155 2
        return Hidden::widget(config: $config, theme: $theme ?? $this->defaultTheme)
156 2
            ->inputData(new PureInputData($name, $value));
157
    }
158
159 3
    final public function image(?string $url = null, array $config = [], ?string $theme = null): Image
160
    {
161 3
        $field = Image::widget(config: $config, theme: $theme ?? $this->defaultTheme);
162
163 3
        if ($url !== null) {
164 1
            $field = $field->src($url);
0 ignored issues
show
Bug introduced by
The method src() 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\Image. ( Ignorable by Annotation )

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

164
            /** @scrutinizer ignore-call */ 
165
            $field = $field->src($url);
Loading history...
165
        }
166
167 3
        return $field;
168
    }
169
170 2
    final public function number(
171
        ?string $name = null,
172
        mixed $value = null,
173
        array $config = [],
174
        ?string $theme = null,
175
    ): Number {
176 2
        return Number::widget(config: $config, theme: $theme ?? $this->defaultTheme)
177 2
            ->inputData(new PureInputData($name, $value));
178
    }
179
180 2
    final public function password(
181
        ?string $name = null,
182
        mixed $value = null,
183
        array $config = [],
184
        ?string $theme = null,
185
    ): Password {
186 2
        return Password::widget(config: $config, theme: $theme ?? $this->defaultTheme)
187 2
            ->inputData(new PureInputData($name, $value));
188
    }
189
190 2
    final public function radioList(
191
        ?string $name = null,
192
        mixed $value = null,
193
        array $config = [],
194
        ?string $theme = null,
195
    ): RadioList {
196 2
        return RadioList::widget(config: $config, theme: $theme ?? $this->defaultTheme)
197 2
            ->inputData(new PureInputData($name, $value));
198
    }
199
200 2
    final public function range(
201
        ?string $name = null,
202
        mixed $value = null,
203
        array $config = [],
204
        ?string $theme = null,
205
    ): Range {
206 2
        return Range::widget(config: $config, theme: $theme ?? $this->defaultTheme)
207 2
            ->inputData(new PureInputData($name, $value));
208
    }
209
210 3
    final public function resetButton(
211
        ?string $content = null,
212
        array $config = [],
213
        ?string $theme = null,
214
    ): ResetButton {
215 3
        $field = ResetButton::widget(config: $config, theme: $theme ?? $this->defaultTheme);
216
217 3
        if ($content !== null) {
218 1
            $field = $field->content($content);
219
        }
220
221 3
        return $field;
222
    }
223
224 2
    final public function select(
225
        ?string $name = null,
226
        mixed $value = null,
227
        array $config = [],
228
        ?string $theme = null,
229
    ): Select {
230 2
        return Select::widget(config: $config, theme: $theme ?? $this->defaultTheme)
231 2
            ->inputData(new PureInputData($name, $value));
232
    }
233
234 3
    final public function submitButton(
235
        ?string $content = null,
236
        array $config = [],
237
        ?string $theme = null,
238
    ): SubmitButton {
239 3
        $field = SubmitButton::widget(config: $config, theme: $theme ?? $this->defaultTheme);
240
241 3
        if ($content !== null) {
242 1
            $field = $field->content($content);
243
        }
244
245 3
        return $field;
246
    }
247
248 2
    final public function telephone(
249
        ?string $name = null,
250
        mixed $value = null,
251
        array $config = [],
252
        ?string $theme = null,
253
    ): Telephone {
254 2
        return Telephone::widget(config: $config, theme: $theme ?? $this->defaultTheme)
255 2
            ->inputData(new PureInputData($name, $value));
256
    }
257
258 2
    final public function text(
259
        ?string $name = null,
260
        mixed $value = null,
261
        array $config = [],
262
        ?string $theme = null,
263
    ): Text {
264 2
        return Text::widget(config: $config, theme: $theme ?? $this->defaultTheme)
265 2
            ->inputData(new PureInputData($name, $value));
266
    }
267
268 2
    final public function textarea(
269
        ?string $name = null,
270
        mixed $value = null,
271
        array $config = [],
272
        ?string $theme = null,
273
    ): Textarea {
274 2
        return Textarea::widget(config: $config, theme: $theme ?? $this->defaultTheme)
275 2
            ->inputData(new PureInputData($name, $value));
276
    }
277
278 2
    final public function time(
279
        ?string $name = null,
280
        mixed $value = null,
281
        array $config = [],
282
        ?string $theme = null,
283
    ): Time {
284 2
        return Time::widget(config: $config, theme: $theme ?? $this->defaultTheme)
285 2
            ->inputData(new PureInputData($name, $value));
286
    }
287
288 2
    final public function url(
289
        ?string $name = null,
290
        mixed $value = null,
291
        array $config = [],
292
        ?string $theme = null,
293
    ): Url {
294 2
        return Url::widget(config: $config, theme: $theme ?? $this->defaultTheme)
295 2
            ->inputData(new PureInputData($name, $value));
296
    }
297
298 3
    final public function label(?string $content = null, array $config = [], ?string $theme = null): Label
299
    {
300 3
        return Label::widget(config: $config, theme: $theme ?? $this->defaultTheme)->content($content);
301
    }
302
303 3
    final public function hint(?string $content = null, array $config = [], ?string $theme = null): Hint
304
    {
305 3
        return Hint::widget(config: $config, theme: $theme ?? $this->defaultTheme)->content($content);
306
    }
307
308 3
    final public function error(?string $message = null, array $config = [], ?string $theme = null): Error
309
    {
310 3
        return Error::widget(config: $config, theme: $theme ?? $this->defaultTheme)->message($message);
0 ignored issues
show
Bug introduced by
The method message() 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\Error. ( Ignorable by Annotation )

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

310
        return Error::widget(config: $config, theme: $theme ?? $this->defaultTheme)->/** @scrutinizer ignore-call */ message($message);
Loading history...
311
    }
312
}
313