@@ -13,6 +13,7 @@ private function __construct() {}
1313 * @param string|int ...$keys the keys for the values to retain
1414 * @return array the resulting array
1515 * @since 1.0
16+ * @phpstan-ignore missingType.iterableValue, missingType.iterableValue
1617 */
1718 public static function pick (array $ array , string |int ...$ keys ): array
1819 {
@@ -26,6 +27,7 @@ public static function pick(array $array, string|int ...$keys): array
2627 * @param bool $return_key whether to return the key instead of the value
2728 * @return mixed the value or the key for a found item, null otherwise
2829 * @since 1.0
30+ * @phpstan-ignore missingType.iterableValue
2931 */
3032 public static function find_by (array $ array , callable $ predicate , bool $ return_key = false ): mixed
3133 {
@@ -40,10 +42,11 @@ public static function find_by(array $array, callable $predicate, bool $return_k
4042 * @param iterable $iterable the elements to reduce
4143 * @param callable(mixed $carry, mixed $value, string|int $key): mixed $callback
4244 * @param mixed $initial an optional initial value. if not passed, the first element is taken as the initial value and the `$callback` is not called for it
43- * @param mixed $on_empty (since 1.2) whether to return the initial value iff the iterable is empty
45+ * @param bool $on_empty (since 1.2) whether to return the initial value iff the iterable is empty
4446 * @return mixed the reduced value, the initial value or the on_empty value (if passed)
4547 * @throws \RuntimeException when the iterable is empty, no initial value was passed and no_empty was not given
4648 * @since 1.0
49+ * @phpstan-ignore missingType.iterableValue
4750 */
4851 public static function reduce (iterable $ iterable , callable $ callback , mixed $ initial = new self (), bool $ on_empty = false ): mixed
4952 {
@@ -58,7 +61,7 @@ public static function reduce(iterable $iterable, callable $callback, mixed $ini
5861 continue ;
5962 }
6063 }
61- $ initial = $ callback ($ initial , $ v , $ k );
64+ $ initial = $ callback ($ initial , $ v , $ k ); // @phpstan-ignore argument.type ($k is definitely of type string|int)
6265 }
6366 if ($ first && !$ has_initial ) {
6467 if ($ initial_set )
@@ -70,9 +73,11 @@ public static function reduce(iterable $iterable, callable $callback, mixed $ini
7073
7174 /**
7275 * Like implode()/join() in legacy syntax, but outputs the keys too and takes an additional parameter `$kv_sep`.
76+ * @param iterable $data the elements to join
7377 * @param string $sep the separator of elements
7478 * @param string $kv_sep the separator for key and value
7579 * @since 1.0
80+ * @phpstan-ignore missingType.iterableValue
7681 */
7782 public static function kvjoin (iterable $ data , string $ sep = ', ' , string $ kv_sep = '= ' ): string
7883 {
@@ -81,7 +86,7 @@ public static function kvjoin(iterable $data, string $sep = ', ', string $kv_sep
8186 foreach ($ data as $ k => $ v ) {
8287 if ($ first ) $ first = false ;
8388 else $ str .= $ sep ;
84- $ str .= $ k . $ kv_sep . $ v ;
89+ $ str .= " $ k $ kv_sep$ v " ; // @phpstan-ignore encapsedStringPart.nonString, encapsedStringPart.nonString
8590 }
8691 return $ str ;
8792 }
@@ -90,13 +95,14 @@ public static function kvjoin(iterable $data, string $sep = ', ', string $kv_sep
9095 * Returns the first mapping (element) of an array as key and value in an array, or null/null if the array is empty.
9196 * Array destructuring is a very convenient way to handle the result: `['k' => $key, 'v' => $value] = Arr::first($array)`
9297 * @param iterable $iterable the source iterable
93- * @return array ['k' => <key>/null, 'v' => <value>/null]
98+ * @return array{k: string|int|null, v: mixed} ['k' => <key>/null, 'v' => <value>/null]
9499 * @since 1.0
100+ * @phpstan-ignore missingType.iterableValue
95101 */
96102 public static function first (iterable $ iterable ): array
97103 {
98104 foreach ($ iterable as $ k => $ v )
99- return compact ('k ' , 'v ' );
105+ return compact ('k ' , 'v ' ); // @phpstan-ignore return.type
100106 return ['k ' => null , 'v ' => null ];
101107 }
102108
@@ -105,8 +111,9 @@ public static function first(iterable $iterable): array
105111 * Array destructuring is a very convenient way to handle the result: `['k' => $key, 'v' => $value] = Arr::find($array, 'key1', 'key2')`
106112 * @param array $array the source array
107113 * @param string|int ...$ks the keys
108- * @return array ['k' => <key>/null, 'v' => <value>/null]
114+ * @return array{k: string|int|null, v: mixed} ['k' => <key>/null, 'v' => <value>/null]
109115 * @since 1.0
116+ * @phpstan-ignore missingType.iterableValue
110117 */
111118 public static function find (array $ array , string |int ...$ ks ): array
112119 {
@@ -115,4 +122,4 @@ public static function find(array $array, string|int ...$ks): array
115122 return compact ('k ' , 'v ' );
116123 return ['k ' => null , 'v ' => null ];
117124 }
118- }
125+ }
0 commit comments