Skip to content

Commit 18206b1

Browse files
authored
Merge pull request #6721 from kenjis/fix-phpdocs-form_helper
refactor: remove unneeded code in form_helper
2 parents 77e5dcf + 0df554b commit 18206b1

3 files changed

Lines changed: 26 additions & 32 deletions

File tree

phpstan-baseline.neon.dist

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,6 @@ parameters:
545545
count: 1
546546
path: system/Helpers/filesystem_helper.php
547547

548-
-
549-
message: "#^Offset 'checked' on array\\{type\\: 'checkbox', name\\: mixed, value\\: string\\} in isset\\(\\) does not exist\\.$#"
550-
count: 1
551-
path: system/Helpers/form_helper.php
552-
553548
-
554549
message: "#^Binary operation \"\\+\" between 0 and string results in an error\\.$#"
555550
count: 1

system/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ function slash_item(string $item): ?string
10541054
* Helper function used to convert a string, array, or object
10551055
* of attributes to a string.
10561056
*
1057-
* @param mixed $attributes string, array, object
1057+
* @param array|object|string $attributes string, array, object that can be cast to array
10581058
*/
10591059
function stringify_attributes($attributes, bool $js = false): string
10601060
{

system/Helpers/form_helper.php

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ function form_hidden($name, $value = '', bool $recursing = false): string
137137
* Text Input Field. If 'type' is passed in the $type field, it will be
138138
* used as the input type, for making 'email', 'phone', etc input fields.
139139
*
140-
* @param mixed $data
141-
* @param mixed $extra
140+
* @param array|string $data
141+
* @param array|object|string $extra string, array, object that can be cast to array
142142
*/
143143
function form_input($data = '', string $value = '', $extra = '', string $type = 'text'): string
144144
{
@@ -158,8 +158,8 @@ function form_input($data = '', string $value = '', $extra = '', string $type =
158158
*
159159
* Identical to the input function but adds the "password" type
160160
*
161-
* @param mixed $data
162-
* @param mixed $extra
161+
* @param array|string $data
162+
* @param array|object|string $extra string, array, object that can be cast to array
163163
*/
164164
function form_password($data = '', string $value = '', $extra = ''): string
165165
{
@@ -178,8 +178,8 @@ function form_password($data = '', string $value = '', $extra = ''): string
178178
*
179179
* Identical to the input function but adds the "file" type
180180
*
181-
* @param mixed $data
182-
* @param mixed $extra
181+
* @param array|string $data
182+
* @param array|object|string $extra string, array, object that can be cast to array
183183
*/
184184
function form_upload($data = '', string $value = '', $extra = ''): string
185185
{
@@ -202,8 +202,8 @@ function form_upload($data = '', string $value = '', $extra = ''): string
202202
/**
203203
* Textarea field
204204
*
205-
* @param mixed $data
206-
* @param mixed $extra
205+
* @param array|string $data
206+
* @param array|object|string $extra string, array, object that can be cast to array
207207
*/
208208
function form_textarea($data = '', string $value = '', $extra = ''): string
209209
{
@@ -238,8 +238,8 @@ function form_textarea($data = '', string $value = '', $extra = ''): string
238238
/**
239239
* Multi-select menu
240240
*
241-
* @param mixed $name
242-
* @param mixed $extra
241+
* @param array|string $name
242+
* @param array|object|string $extra string, array, object that can be cast to array
243243
*/
244244
function form_multiselect($name = '', array $options = [], array $selected = [], $extra = ''): string
245245
{
@@ -257,10 +257,10 @@ function form_multiselect($name = '', array $options = [], array $selected = [],
257257
/**
258258
* Drop-down Menu
259259
*
260-
* @param mixed $data
261-
* @param mixed $options
262-
* @param mixed $selected
263-
* @param mixed $extra
260+
* @param array|string $data
261+
* @param array|string $options
262+
* @param array|string $selected
263+
* @param array|object|string $extra string, array, object that can be cast to array
264264
*/
265265
function form_dropdown($data = '', $options = [], $selected = [], $extra = ''): string
266266
{
@@ -340,8 +340,8 @@ function form_dropdown($data = '', $options = [], $selected = [], $extra = ''):
340340
/**
341341
* Checkbox Field
342342
*
343-
* @param mixed $data
344-
* @param mixed $extra
343+
* @param array|string $data
344+
* @param array|object|string $extra string, array, object that can be cast to array
345345
*/
346346
function form_checkbox($data = '', string $value = '', bool $checked = false, $extra = ''): string
347347
{
@@ -353,6 +353,7 @@ function form_checkbox($data = '', string $value = '', bool $checked = false, $e
353353

354354
if (is_array($data) && array_key_exists('checked', $data)) {
355355
$checked = $data['checked'];
356+
356357
if ($checked === false) {
357358
unset($data['checked']);
358359
} else {
@@ -362,8 +363,6 @@ function form_checkbox($data = '', string $value = '', bool $checked = false, $e
362363

363364
if ($checked === true) {
364365
$defaults['checked'] = 'checked';
365-
} elseif (isset($defaults['checked'])) {
366-
unset($defaults['checked']);
367366
}
368367

369368
return '<input ' . parse_form_attributes($data, $defaults) . stringify_attributes($extra) . " />\n";
@@ -374,8 +373,8 @@ function form_checkbox($data = '', string $value = '', bool $checked = false, $e
374373
/**
375374
* Radio Button
376375
*
377-
* @param mixed $data
378-
* @param mixed $extra
376+
* @param array|string $data
377+
* @param array|object|string $extra string, array, object that can be cast to array
379378
*/
380379
function form_radio($data = '', string $value = '', bool $checked = false, $extra = ''): string
381380
{
@@ -392,8 +391,8 @@ function form_radio($data = '', string $value = '', bool $checked = false, $extr
392391
/**
393392
* Submit Button
394393
*
395-
* @param mixed $data
396-
* @param mixed $extra
394+
* @param array|string $data
395+
* @param array|object|string $extra string, array, object that can be cast to array
397396
*/
398397
function form_submit($data = '', string $value = '', $extra = ''): string
399398
{
@@ -405,8 +404,8 @@ function form_submit($data = '', string $value = '', $extra = ''): string
405404
/**
406405
* Reset Button
407406
*
408-
* @param mixed $data
409-
* @param mixed $extra
407+
* @param array|string $data
408+
* @param array|object|string $extra string, array, object that can be cast to array
410409
*/
411410
function form_reset($data = '', string $value = '', $extra = ''): string
412411
{
@@ -418,8 +417,8 @@ function form_reset($data = '', string $value = '', $extra = ''): string
418417
/**
419418
* Form Button
420419
*
421-
* @param mixed $data
422-
* @param mixed $extra
420+
* @param array|string $data
421+
* @param array|object|string $extra string, array, object that can be cast to array
423422
*/
424423
function form_button($data = '', string $content = '', $extra = ''): string
425424
{

0 commit comments

Comments
 (0)