Passed
Push — master ( a265ce...b92c2f )
by Sergei
04:01 queued 01:03
created

PureField::errorSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 6
ccs 2
cts 2
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 PureField
41
{
42
    /**
43
     * @var string|null
44
     */
45
    protected const DEFAULT_THEME = null;
46
47 3
    final public static function button(?string $content = null, array $config = [], ?string $theme = null): Button
48
    {
49 3
        $field = Button::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
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 static function buttonGroup(array $config = [], ?string $theme = null): ButtonGroup
59
    {
60 2
        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...
61
    }
62
63 2
    final public static 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 ?? static::DEFAULT_THEME)
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 static 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 ?? static::DEFAULT_THEME)
80 2
            ->inputData(new PureInputData($name, $value));
81
    }
82
83 2
    final public static 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 ?? static::DEFAULT_THEME)
90 2
            ->inputData(new PureInputData($name, $value));
91
    }
92
93 2
    final public static 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 ?? static::DEFAULT_THEME)
100 2
            ->inputData(new PureInputData($name, $value));
101
    }
102
103 2
    final public static 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 ?? static::DEFAULT_THEME)
110 2
            ->inputData(new PureInputData($name, $value));
111
    }
112
113 2
    final public static 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 ?? static::DEFAULT_THEME)
120 2
            ->inputData(new PureInputData($name, $value));
121
    }
122
123
    /**
124
     * @psalm-param Errors $errors
125
     */
126 2
    final public static function errorSummary(
127
        array $errors = [],
128
        array $config = [],
129
        ?string $theme = null,
130
    ): ErrorSummary {
131 2
        return ErrorSummary::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)->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 ?? static::DEFAULT_THEME)->/** @scrutinizer ignore-call */ errors($errors);
Loading history...
132
    }
133
134 2
    final public static function fieldset(array $config = [], ?string $theme = null): Fieldset
135
    {
136 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...
137
    }
138
139 2
    final public static 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 ?? static::DEFAULT_THEME)
146 2
            ->inputData(new PureInputData($name, $value));
147
    }
148
149 3
    final public static function hidden(
150
        ?string $name = null,
151
        mixed $value = null,
152
        array $config = [],
153
        ?string $theme = null,
154
    ): Hidden {
155 3
        return Hidden::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
156 3
            ->inputData(new PureInputData($name, $value));
157
    }
158
159 2
    final public static function image(array $config = [], ?string $theme = null): Image
160
    {
161 2
        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...
162
    }
163
164 2
    final public static function number(
165
        ?string $name = null,
166
        mixed $value = null,
167
        array $config = [],
168
        ?string $theme = null,
169
    ): Number {
170 2
        return Number::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
171 2
            ->inputData(new PureInputData($name, $value));
172
    }
173
174 2
    final public static function password(
175
        ?string $name = null,
176
        mixed $value = null,
177
        array $config = [],
178
        ?string $theme = null,
179
    ): Password {
180 2
        return Password::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
181 2
            ->inputData(new PureInputData($name, $value));
182
    }
183
184 2
    final public static function radioList(
185
        ?string $name = null,
186
        mixed $value = null,
187
        array $config = [],
188
        ?string $theme = null,
189
    ): RadioList {
190 2
        return RadioList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
191 2
            ->inputData(new PureInputData($name, $value));
192
    }
193
194 2
    final public static function range(
195
        ?string $name = null,
196
        mixed $value = null,
197
        array $config = [],
198
        ?string $theme = null,
199
    ): Range {
200 2
        return Range::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
201 2
            ->inputData(new PureInputData($name, $value));
202
    }
203
204 3
    final public static function resetButton(
205
        ?string $content = null,
206
        array $config = [],
207
        ?string $theme = null,
208
    ): ResetButton {
209 3
        $field = ResetButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
210
211 3
        if ($content !== null) {
212 1
            $field = $field->content($content);
213
        }
214
215 3
        return $field;
216
    }
217
218 2
    final public static function select(
219
        ?string $name = null,
220
        mixed $value = null,
221
        array $config = [],
222
        ?string $theme = null,
223
    ): Select {
224 2
        return Select::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
225 2
            ->inputData(new PureInputData($name, $value));
226
    }
227
228 3
    final public static function submitButton(
229
        ?string $content = null,
230
        array $config = [],
231
        ?string $theme = null,
232
    ): SubmitButton {
233 3
        $field = SubmitButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
234
235 3
        if ($content !== null) {
236 1
            $field = $field->content($content);
237
        }
238
239 3
        return $field;
240
    }
241
242 2
    final public static function telephone(
243
        ?string $name = null,
244
        mixed $value = null,
245
        array $config = [],
246
        ?string $theme = null,
247
    ): Telephone {
248 2
        return Telephone::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
249 2
            ->inputData(new PureInputData($name, $value));
250
    }
251
252 4
    final public static function text(
253
        ?string $name = null,
254
        mixed $value = null,
255
        array $config = [],
256
        ?string $theme = null,
257
    ): Text {
258 4
        return Text::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
259 4
            ->inputData(new PureInputData($name, $value));
260
    }
261
262 2
    final public static function textarea(
263
        ?string $name = null,
264
        mixed $value = null,
265
        array $config = [],
266
        ?string $theme = null,
267
    ): Textarea {
268 2
        return Textarea::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
269 2
            ->inputData(new PureInputData($name, $value));
270
    }
271
272 2
    final public static function time(
273
        ?string $name = null,
274
        mixed $value = null,
275
        array $config = [],
276
        ?string $theme = null,
277
    ): Time {
278 2
        return Time::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
279 2
            ->inputData(new PureInputData($name, $value));
280
    }
281
282 2
    final public static function url(
283
        ?string $name = null,
284
        mixed $value = null,
285
        array $config = [],
286
        ?string $theme = null,
287
    ): Url {
288 2
        return Url::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
289 2
            ->inputData(new PureInputData($name, $value));
290
    }
291
292 3
    final public static function label(?string $content = null, array $config = [], ?string $theme = null): Label
293
    {
294 3
        return Label::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)->content($content);
295
    }
296
297 3
    final public static function hint(?string $content = null, array $config = [], ?string $theme = null): Hint
298
    {
299 3
        return Hint::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)->content($content);
300
    }
301
302 3
    final public static function error(?string $message = null, array $config = [], ?string $theme = null): Error
303
    {
304 3
        return Error::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)->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

304
        return Error::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)->/** @scrutinizer ignore-call */ message($message);
Loading history...
305
    }
306
}
307