Skip to content

Commit edd258d

Browse files
committed
fix(Functions): Array slice params
1 parent 1e3392e commit edd258d

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

xwp-helper-fns-arr.php

+18-15
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,31 @@ function wp_array_flatmap_assoc( callable $callback, array $input, string $key,
6767
/**
6868
* Legacy function to extract a slice of an array not including the specified keys.
6969
*
70-
* @param array $input_array Input array.
71-
* @param array $keys Keys to exclude.
70+
* @template T of array<string,mixed>
71+
*
72+
* @param T $arr Input array.
73+
* @param array<string> $keys Keys to exclude.
74+
* @return T
7275
*/
73-
function wp_array_diff_assoc( array $input_array, array $keys ) {
74-
return xwp_array_diff_assoc( $input_array, ...$keys );
76+
function wp_array_diff_assoc( array $arr, array $keys ) {
77+
return xwp_array_diff_assoc( $arr, ...$keys );
7578
}
7679
endif;
7780

7881
if ( ! function_exists( 'xwp_array_diff_assoc' ) ) :
7982
/**
8083
* Extracts a slice of array not including the specified keys.
8184
*
82-
* @template T
85+
* @template T of array<string,mixed>
8386
*
8487
* @param T $arr Input array.
8588
* @param string|array<string> ...$keys Keys to exclude.
8689
* @return T
8790
*/
8891
function xwp_array_diff_assoc( array $arr, array|string ...$keys ) {
89-
if ( is_array( $keys[0] ) ) {
90-
$keys = $keys[0];
91-
}
92+
$keys = is_array( $keys[0] ?? '' ) ? $keys[0] : $keys;
9293

93-
return f\Array_Extra::diff_assoc( $arr, $keys );
94+
return $keys ? f\Array_Extra::diff_assoc( $arr, $keys ) : $arr;
9495
}
9596

9697
endif;
@@ -112,14 +113,16 @@ function wp_array_rekey( array $arr, string $key ): array {
112113
/**
113114
* Extracts a slice of an array.
114115
*
115-
* @template T The type of the elements in the input array.
116+
* @template T of array<string,mixed>
116117
*
117-
* @param array<string, T> $input_array Input array.
118-
* @param string ...$keys Keys to include.
119-
* @return array<string, T> Array with only the keys specified.
118+
* @param T $arr Input array.
119+
* @param string|array<string> ...$keys Keys to exclude.
120+
* @return T
120121
*/
121-
function xwp_array_slice_assoc( array $input_array, string ...$keys ) {
122-
return f\Array_Extra::slice_assoc( $input_array, $keys );
122+
function xwp_array_slice_assoc( array $arr, array|string ...$keys ) {
123+
$keys = is_array( $keys[0] ?? '' ) ? $keys[0] : $keys;
124+
125+
return $keys ? f\Array_Extra::slice_assoc( $arr, $keys ) : $arr;
123126
}
124127
endif;
125128

xwp-helper-fns.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function xwp_parse_args( string|array|object $args, array $defaults = array() ):
4949
* @return TFS|false|null
5050
*/
5151
function xwp_wpfs(
52-
string $method = null,
52+
string $method = WP_Filesystem_Direct::class,
5353
array|bool $args = false,
5454
string|bool $context = false,
5555
): WP_Filesystem_Base|bool|null {

0 commit comments

Comments
 (0)