Skip to content

Commit 46fb984

Browse files
committed
refactor: fix phpstan errors in Helpers
1 parent e3a8f37 commit 46fb984

13 files changed

Lines changed: 155 additions & 594 deletions

system/Helpers/Array/ArrayHelper.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ final class ArrayHelper
3333
*
3434
* @used-by dot_array_search()
3535
*
36-
* @param string $index The index as dot array syntax.
36+
* @param string $index The index as dot array syntax.
37+
* @param array<array-key, mixed> $array
3738
*
3839
* @return mixed
3940
*/
@@ -68,6 +69,9 @@ private static function convertToArray(string $index): array
6869
*
6970
* @used-by dotSearch()
7071
*
72+
* @param list<string> $indexes
73+
* @param array<array-key, mixed> $array
74+
*
7175
* @return mixed
7276
*/
7377
private static function arraySearchDot(array $indexes, array $array)
@@ -125,6 +129,8 @@ private static function arraySearchDot(array $indexes, array $array)
125129
* array_key_exists() with dot array syntax.
126130
*
127131
* If wildcard `*` is used, all items for the key after it must have the key.
132+
*
133+
* @param array<array-key, mixed> $array
128134
*/
129135
public static function dotKeyExists(string $index, array $array): bool
130136
{
@@ -179,11 +185,11 @@ public static function dotKeyExists(string $index, array $array): bool
179185
*
180186
* @used-by array_group_by()
181187
*
182-
* @param array $array Data array (i.e. from query result)
183-
* @param array $indexes Indexes to group by. Dot syntax used. Returns $array if empty
184-
* @param bool $includeEmpty If true, null and '' are also added as valid keys to group
188+
* @param array<array-key, mixed> $array Data array (i.e. from query result)
189+
* @param list<string> $indexes Indexes to group by. Dot syntax used. Returns $array if empty
190+
* @param bool $includeEmpty If true, null and '' are also added as valid keys to group
185191
*
186-
* @return array Result array where rows are grouped together by indexes values.
192+
* @return array<array-key, mixed> Result array where rows are grouped together by indexes values.
187193
*/
188194
public static function groupBy(array $array, array $indexes, bool $includeEmpty = false): array
189195
{
@@ -205,6 +211,12 @@ public static function groupBy(array $array, array $indexes, bool $includeEmpty
205211
* `dot_array_search()`.
206212
*
207213
* @used-by groupBy()
214+
*
215+
* @param array<array-key, mixed> $result
216+
* @param array<array-key, mixed> $row
217+
* @param list<string> $indexes
218+
*
219+
* @return array<array-key, mixed>
208220
*/
209221
private static function arrayAttachIndexedValue(
210222
array $result,
@@ -244,6 +256,11 @@ private static function arrayAttachIndexedValue(
244256
/**
245257
* Compare recursively two associative arrays and return difference as new array.
246258
* Returns keys that exist in `$original` but not in `$compareWith`.
259+
*
260+
* @param array<array-key, mixed> $original
261+
* @param array<array-key, mixed> $compareWith
262+
*
263+
* @return array<array-key, mixed>
247264
*/
248265
public static function recursiveDiff(array $original, array $compareWith): array
249266
{
@@ -284,6 +301,8 @@ public static function recursiveDiff(array $original, array $compareWith): array
284301

285302
/**
286303
* Recursively count all keys.
304+
*
305+
* @param array<array-key, mixed> $array
287306
*/
288307
public static function recursiveCount(array $array, int $counter = 0): int
289308
{

system/Helpers/array_helper.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* Searches an array through dot syntax. Supports
2121
* wildcard searches, like foo.*.bar
2222
*
23+
* @param array<array-key, mixed> $array
24+
*
2325
* @return mixed
2426
*/
2527
function dot_array_search(string $index, array $array)
@@ -32,7 +34,8 @@ function dot_array_search(string $index, array $array)
3234
/**
3335
* Returns the value of an element at a key in an array of uncertain depth.
3436
*
35-
* @param int|string $key
37+
* @param int|string $key
38+
* @param array<array-key, mixed> $array
3639
*
3740
* @return mixed
3841
*/
@@ -78,9 +81,9 @@ function array_deep_search($key, array $array)
7881
* For information on multi-level array sorting, refer to Example #3 here:
7982
* https://www.php.net/manual/de/function.array-multisort.php
8083
*
81-
* @param array $array the reference of the array to be sorted
82-
* @param array $sortColumns an associative array of columns to sort
83-
* after and their sorting flags
84+
* @param array<array-key, mixed> $array The reference of the array to be sorted
85+
* @param array<string, int> $sortColumns An associative array of columns to sort
86+
* after and their sorting flags
8487
*/
8588
function array_sort_by_multiple_keys(array &$array, array $sortColumns): bool
8689
{
@@ -129,10 +132,10 @@ function array_sort_by_multiple_keys(array &$array, array $sortColumns): bool
129132
/**
130133
* Flatten a multidimensional array using dots as separators.
131134
*
132-
* @param iterable $array The multi-dimensional array
133-
* @param string $id Something to initially prepend to the flattened keys
135+
* @param iterable<array-key, mixed> $array The multi-dimensional array
136+
* @param string $id Something to initially prepend to the flattened keys
134137
*
135-
* @return array The flattened array
138+
* @return array<string, mixed> The flattened array
136139
*/
137140
function array_flatten_with_dots(iterable $array, string $id = ''): array
138141
{
@@ -156,11 +159,11 @@ function array_flatten_with_dots(iterable $array, string $id = ''): array
156159
/**
157160
* Groups all rows by their index values. Result's depth equals number of indexes
158161
*
159-
* @param array $array Data array (i.e. from query result)
160-
* @param array $indexes Indexes to group by. Dot syntax used. Returns $array if empty
161-
* @param bool $includeEmpty If true, null and '' are also added as valid keys to group
162+
* @param array<array-key, mixed> $array Data array (i.e. from query result)
163+
* @param list<string> $indexes Indexes to group by. Dot syntax used. Returns $array if empty
164+
* @param bool $includeEmpty If true, null and '' are also added as valid keys to group
162165
*
163-
* @return array Result array where rows are grouped together by indexes values.
166+
* @return array<array-key, mixed> Result array where rows are grouped together by indexes values.
164167
*/
165168
function array_group_by(array $array, array $indexes, bool $includeEmpty = false): array
166169
{

system/Helpers/filesystem_helper.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
* directory will be mapped as well.
2525
*
2626
* @param string $sourceDir Path to source
27-
* @param int $directoryDepth Depth of directories to traverse
28-
* (0 = fully recursive, 1 = current dir, etc)
27+
* @param int $directoryDepth Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)
2928
* @param bool $hidden Whether to show hidden files
29+
*
30+
* @return array<array-key, array<array-key, mixed>|string>
3031
*/
3132
function directory_map(string $sourceDir, int $directoryDepth = 0, bool $hidden = false): array
3233
{
@@ -200,6 +201,8 @@ function delete_files(string $path, bool $delDir = false, bool $htdocs = false,
200201
* @param bool|null $includePath Whether to include the path as part of the filename; false for no path, null for a relative path, true for full path
201202
* @param bool $hidden Whether to include hidden files (files beginning with a period)
202203
* @param bool $includeDir Whether to include directories
204+
*
205+
* @return list<string>
203206
*/
204207
function get_filenames(
205208
string $sourceDir,

system/Helpers/form_helper.php

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*
2424
* Creates the opening portion of the form.
2525
*
26-
* @param string $action the URI segments of the form destination
27-
* @param array|string $attributes a key/value pair of attributes, or string representation
28-
* @param array $hidden a key/value pair hidden data
26+
* @param string $action The URI segments of the form destination
27+
* @param array<string, scalar|null>|string $attributes A key/value pair of attributes, or string representation
28+
* @param array<string, mixed> $hidden A key/value pair hidden data
2929
*/
3030
function form_open(string $action = '', $attributes = [], array $hidden = []): string
3131
{
@@ -80,9 +80,9 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s
8080
*
8181
* Creates the opening portion of the form, but with "multipart/form-data".
8282
*
83-
* @param string $action The URI segments of the form destination
84-
* @param array|string $attributes A key/value pair of attributes, or the same as a string
85-
* @param array $hidden A key/value pair hidden data
83+
* @param string $action The URI segments of the form destination
84+
* @param array<string, scalar|null>|string $attributes A key/value pair of attributes, or the same as a string
85+
* @param array<string, mixed> $hidden A key/value pair hidden data
8686
*/
8787
function form_open_multipart(string $action = '', $attributes = [], array $hidden = []): string
8888
{
@@ -103,8 +103,8 @@ function form_open_multipart(string $action = '', $attributes = [], array $hidde
103103
* Generates hidden fields. You can pass a simple key/value string or
104104
* an associative array with multiple values.
105105
*
106-
* @param array|string $name Field name or associative array to create multiple fields
107-
* @param array|string $value Field value
106+
* @param array<string, mixed>|string $name Field name or associative array to create multiple fields
107+
* @param array<array-key, mixed>|string|null $value Field value
108108
*/
109109
function form_hidden($name, $value = '', bool $recursing = false): string
110110
{
@@ -140,8 +140,8 @@ function form_hidden($name, $value = '', bool $recursing = false): string
140140
* Text Input Field. If 'type' is passed in the $type field, it will be
141141
* used as the input type, for making 'email', 'phone', etc input fields.
142142
*
143-
* @param array|string $data
144-
* @param array|object|string $extra string, array, object that can be cast to array
143+
* @param array<string, scalar|null>|string $data
144+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
145145
*/
146146
function form_input($data = '', string $value = '', $extra = '', string $type = 'text'): string
147147
{
@@ -161,8 +161,8 @@ function form_input($data = '', string $value = '', $extra = '', string $type =
161161
*
162162
* Identical to the input function but adds the "password" type
163163
*
164-
* @param array|string $data
165-
* @param array|object|string $extra string, array, object that can be cast to array
164+
* @param array<string, scalar|null>|string $data
165+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
166166
*/
167167
function form_password($data = '', string $value = '', $extra = ''): string
168168
{
@@ -181,8 +181,8 @@ function form_password($data = '', string $value = '', $extra = ''): string
181181
*
182182
* Identical to the input function but adds the "file" type
183183
*
184-
* @param array|string $data
185-
* @param array|object|string $extra string, array, object that can be cast to array
184+
* @param array<string, scalar|null>|string $data
185+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
186186
*/
187187
function form_upload($data = '', string $value = '', $extra = ''): string
188188
{
@@ -205,8 +205,8 @@ function form_upload($data = '', string $value = '', $extra = ''): string
205205
/**
206206
* Textarea field
207207
*
208-
* @param array|string $data
209-
* @param array|object|string $extra string, array, object that can be cast to array
208+
* @param array<string, scalar|null>|string $data
209+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
210210
*/
211211
function form_textarea($data = '', string $value = '', $extra = ''): string
212212
{
@@ -241,8 +241,10 @@ function form_textarea($data = '', string $value = '', $extra = ''): string
241241
/**
242242
* Multi-select menu
243243
*
244-
* @param array|string $name
245-
* @param array|object|string $extra string, array, object that can be cast to array
244+
* @param array<string, mixed>|string $name
245+
* @param array<array-key, array<array-key, string>|string> $options
246+
* @param array<array-key, int|string> $selected
247+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
246248
*/
247249
function form_multiselect($name = '', array $options = [], array $selected = [], $extra = ''): string
248250
{
@@ -260,10 +262,10 @@ function form_multiselect($name = '', array $options = [], array $selected = [],
260262
/**
261263
* Drop-down Menu
262264
*
263-
* @param array|string $data
264-
* @param array|string $options
265-
* @param array|string $selected
266-
* @param array|object|string $extra string, array, object that can be cast to array
265+
* @param array<string, mixed>|string $data
266+
* @param array<array-key, array<array-key, string>|string>|string $options
267+
* @param array<array-key, int|string>|string $selected
268+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
267269
*/
268270
function form_dropdown($data = '', $options = [], $selected = [], $extra = ''): string
269271
{
@@ -348,8 +350,8 @@ function form_dropdown($data = '', $options = [], $selected = [], $extra = ''):
348350
/**
349351
* Checkbox Field
350352
*
351-
* @param array|string $data
352-
* @param array|object|string $extra string, array, object that can be cast to array
353+
* @param array<string, scalar|null>|string $data
354+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
353355
*/
354356
function form_checkbox($data = '', string $value = '', bool $checked = false, $extra = ''): string
355357
{
@@ -381,8 +383,8 @@ function form_checkbox($data = '', string $value = '', bool $checked = false, $e
381383
/**
382384
* Radio Button
383385
*
384-
* @param array|string $data
385-
* @param array|object|string $extra string, array, object that can be cast to array
386+
* @param array<string, scalar|null>|string $data
387+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
386388
*/
387389
function form_radio($data = '', string $value = '', bool $checked = false, $extra = ''): string
388390
{
@@ -399,8 +401,8 @@ function form_radio($data = '', string $value = '', bool $checked = false, $extr
399401
/**
400402
* Submit Button
401403
*
402-
* @param array|string $data
403-
* @param array|object|string $extra string, array, object that can be cast to array
404+
* @param array<string, scalar|null>|string $data
405+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
404406
*/
405407
function form_submit($data = '', string $value = '', $extra = ''): string
406408
{
@@ -412,8 +414,8 @@ function form_submit($data = '', string $value = '', $extra = ''): string
412414
/**
413415
* Reset Button
414416
*
415-
* @param array|string $data
416-
* @param array|object|string $extra string, array, object that can be cast to array
417+
* @param array<string, scalar|null>|string $data
418+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
417419
*/
418420
function form_reset($data = '', string $value = '', $extra = ''): string
419421
{
@@ -425,8 +427,8 @@ function form_reset($data = '', string $value = '', $extra = ''): string
425427
/**
426428
* Form Button
427429
*
428-
* @param array|string $data
429-
* @param array|object|string $extra string, array, object that can be cast to array
430+
* @param array<string, scalar|null>|string $data
431+
* @param array<string, scalar|null>|object|string $extra String, array, object that can be cast to array
430432
*/
431433
function form_button($data = '', string $content = '', $extra = ''): string
432434
{
@@ -450,9 +452,9 @@ function form_button($data = '', string $content = '', $extra = ''): string
450452
/**
451453
* Form Label Tag
452454
*
453-
* @param string $labelText The text to appear onscreen
454-
* @param string $id The id the label applies to
455-
* @param array $attributes Additional attributes
455+
* @param string $labelText The text to appear onscreen
456+
* @param string $id The id the label applies to
457+
* @param array<string, scalar|null> $attributes Additional attributes
456458
*/
457459
function form_label(string $labelText = '', string $id = '', array $attributes = []): string
458460
{
@@ -477,6 +479,8 @@ function form_label(string $labelText = '', string $id = '', array $attributes =
477479
* The <datalist> element specifies a list of pre-defined options for an <input> element.
478480
* Users will see a drop-down list of pre-defined options as they input data.
479481
* The list attribute of the <input> element, must refer to the id attribute of the <datalist> element.
482+
*
483+
* @param list<string> $options
480484
*/
481485
function form_datalist(string $name, string $value, array $options): string
482486
{
@@ -506,8 +510,8 @@ function form_datalist(string $name, string $value, array $options): string
506510
* Used to produce <fieldset><legend>text</legend>. To close fieldset
507511
* use form_fieldset_close()
508512
*
509-
* @param string $legendText The legend text
510-
* @param array $attributes Additional attributes
513+
* @param string $legendText The legend text
514+
* @param array<string, scalar|null> $attributes Additional attributes
511515
*/
512516
function form_fieldset(string $legendText = '', array $attributes = []): string
513517
{
@@ -770,8 +774,8 @@ function validation_show_error(string $field, string $template = 'single'): stri
770774
*
771775
* @internal
772776
*
773-
* @param array|string $attributes List of attributes
774-
* @param array $default Default values
777+
* @param array<string, scalar|null>|string $attributes List of attributes
778+
* @param array<string, scalar|null> $default Default values
775779
*/
776780
function parse_form_attributes($attributes, array $default): string
777781
{

0 commit comments

Comments
 (0)