Passed
Push — master ( 55e218...1de924 )
by Sergei
04:29 queued 01:39
created

PureField   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 254
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 56
c 2
b 0
f 0
dl 0
loc 254
ccs 81
cts 81
cp 1
rs 10
wmc 30

27 Methods

Rating   Name   Duplication   Size   Complexity  
A time() 0 8 1
A text() 0 8 1
A hidden() 0 8 1
A textarea() 0 8 1
A hint() 0 3 1
A buttonGroup() 0 3 1
A url() 0 8 1
A checkbox() 0 8 1
A fieldset() 0 3 1
A label() 0 3 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 button() 0 9 2
A file() 0 8 1
A error() 0 3 1
A dateTimeLocal() 0 8 1
A range() 0 8 1
A email() 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 2
    final public static function button(?string $content = null, array $config = [], ?string $theme = null): Button
44
    {
45 2
        $field = Button::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
46
47 2
        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 2
        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
        ?string $name = null,
61
        mixed $value = null,
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 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 1
    final public static function checkboxList(
70
        ?string $name = null,
71
        mixed $value = null,
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 PureInputData($name, $value));
77
    }
78
79 1
    final public static function date(
80
        ?string $name = null,
81
        mixed $value = null,
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 PureInputData($name, $value));
87
    }
88
89 1
    final public static function dateTime(
90
        ?string $name = null,
91
        mixed $value = null,
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 PureInputData($name, $value));
97
    }
98
99 1
    final public static function dateTimeLocal(
100
        ?string $name = null,
101
        mixed $value = null,
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 PureInputData($name, $value));
107
    }
108
109 1
    final public static function email(
110
        ?string $name = null,
111
        mixed $value = null,
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 PureInputData($name, $value));
117
    }
118
119 1
    final public static function fieldset(array $config = [], ?string $theme = null): Fieldset
120
    {
121 1
        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 1
    final public static function file(
125
        ?string $name = null,
126
        mixed $value = null,
127
        array $config = [],
128
        ?string $theme = null,
129
    ): File {
130 1
        return File::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
131 1
            ->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 1
    final public static function image(array $config = [], ?string $theme = null): Image
145
    {
146 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...
147
    }
148
149 1
    final public static function number(
150
        ?string $name = null,
151
        mixed $value = null,
152
        array $config = [],
153
        ?string $theme = null,
154
    ): Number {
155 1
        return Number::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
156 1
            ->inputData(new PureInputData($name, $value));
157
    }
158
159 1
    final public static function password(
160
        ?string $name = null,
161
        mixed $value = null,
162
        array $config = [],
163
        ?string $theme = null,
164
    ): Password {
165 1
        return Password::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
166 1
            ->inputData(new PureInputData($name, $value));
167
    }
168
169 1
    final public static function radioList(
170
        ?string $name = null,
171
        mixed $value = null,
172
        array $config = [],
173
        ?string $theme = null,
174
    ): RadioList {
175 1
        return RadioList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
176 1
            ->inputData(new PureInputData($name, $value));
177
    }
178
179 1
    final public static function range(
180
        ?string $name = null,
181
        mixed $value = null,
182
        array $config = [],
183
        ?string $theme = null,
184
    ): Range {
185 1
        return Range::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
186 1
            ->inputData(new PureInputData($name, $value));
187
    }
188
189 2
    final public static function resetButton(
190
        ?string $content = null,
191
        array $config = [],
192
        ?string $theme = null,
193
    ): ResetButton {
194 2
        $field = ResetButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
195
196 2
        if ($content !== null) {
197 1
            $field = $field->content($content);
198
        }
199
200 2
        return $field;
201
    }
202
203 1
    final public static function select(
204
        ?string $name = null,
205
        mixed $value = null,
206
        array $config = [],
207
        ?string $theme = null,
208
    ): Select {
209 1
        return Select::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
210 1
            ->inputData(new PureInputData($name, $value));
211
    }
212
213 2
    final public static function submitButton(
214
        ?string $content = null,
215
        array $config = [],
216
        ?string $theme = null,
217
    ): SubmitButton {
218 2
        $field = SubmitButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
219
220 2
        if ($content !== null) {
221 1
            $field = $field->content($content);
222
        }
223
224 2
        return $field;
225
    }
226
227 1
    final public static function telephone(
228
        ?string $name = null,
229
        mixed $value = null,
230
        array $config = [],
231
        ?string $theme = null,
232
    ): Telephone {
233 1
        return Telephone::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
234 1
            ->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 1
    final public static function textarea(
248
        ?string $name = null,
249
        mixed $value = null,
250
        array $config = [],
251
        ?string $theme = null,
252
    ): Textarea {
253 1
        return Textarea::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
254 1
            ->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 1
    final public static function url(
268
        ?string $name = null,
269
        mixed $value = null,
270
        array $config = [],
271
        ?string $theme = null,
272
    ): Url {
273 1
        return Url::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
274 1
            ->inputData(new PureInputData($name, $value));
275
    }
276
277 2
    final public static function label(?string $content = null, array $config = [], ?string $theme = null): Label
278
    {
279 2
        return Label::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)->content($content);
280
    }
281
282 2
    final public static function hint(?string $content = null, array $config = [], ?string $theme = null): Hint
283
    {
284 2
        return Hint::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)->content($content);
285
    }
286
287 2
    final public static function error(?string $message = null, array $config = [], ?string $theme = null): Error
288
    {
289 2
        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

289
        return Error::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)->/** @scrutinizer ignore-call */ message($message);
Loading history...
290
    }
291
}
292