55namespace Php \Support \Helpers ;
66
77use ArrayAccess ;
8+ use ArrayObject ;
89use JsonSerializable ;
910use Php \Support \Interfaces \Arrayable ;
1011use Php \Support \Interfaces \Jsonable ;
@@ -68,7 +69,7 @@ public static function toArray($items): array
6869 }
6970 }
7071
71- return $ res ;
72+ return ( array ) $ res ;
7273 }
7374
7475 /**
@@ -209,14 +210,14 @@ public static function toIndexedArray(array $array): array
209210 *
210211 * @param string|null $s
211212 * @param int $start
212- * @param null $end
213+ * @param ?int $end
213214 *
214215 * @return array
215216 */
216217 public static function fromPostgresArrayWithBraces (
217218 ?string $ s ,
218219 int $ start = 0 ,
219- &$ end = null ,
220+ ? int &$ end = null ,
220221 array $ braces = [
221222 '{ ' ,
222223 '} ' ,
@@ -284,11 +285,23 @@ public static function fromPostgresArrayWithBraces(
284285 return $ return ;
285286 }
286287
287- public static function fromPostgresArray (?string $ s , int $ start = 0 , &$ end = null ): array
288+ /**
289+ * @param string|null $s
290+ * @param int $start
291+ * @param ?int $end
292+ *
293+ * @return array
294+ */
295+ public static function fromPostgresArray (?string $ s , int $ start = 0 , ?int &$ end = null ): array
288296 {
289297 return static ::fromPostgresArrayWithBraces ($ s , $ start , $ end , ['{ ' , '} ' ]);
290298 }
291299
300+ /**
301+ * @param string|null $value
302+ *
303+ * @return array|null
304+ */
292305 public static function fromPostgresPoint (?string $ value ): ?array
293306 {
294307 if (empty ($ value )) {
@@ -312,7 +325,7 @@ public static function fromPostgresPoint(?string $value): ?array
312325 *
313326 * @return mixed
314327 */
315- public static function get ($ array , ?string $ key , $ default = null )
328+ public static function get (mixed $ array , ?string $ key , mixed $ default = null ): mixed
316329 {
317330 if (!static ::accessible ($ array )) {
318331 return value ($ default );
@@ -322,11 +335,12 @@ public static function get($array, ?string $key, $default = null)
322335 return $ array ;
323336 }
324337
338+ /** @var array|ArrayAccess $array */
325339 if (static ::exists ($ array , $ key )) {
326340 return $ array [$ key ];
327341 }
328342
329- if (strpos ($ key , '. ' ) === false ) {
343+ if (! str_contains ($ key , '. ' )) {
330344 return $ array [$ key ] ?? value ($ default );
331345 }
332346
@@ -348,7 +362,7 @@ public static function get($array, ?string $key, $default = null)
348362 *
349363 * @return bool
350364 */
351- public static function accessible ($ value ): bool
365+ public static function accessible (mixed $ value ): bool
352366 {
353367 return is_array ($ value ) || $ value instanceof ArrayAccess;
354368 }
@@ -361,7 +375,7 @@ public static function accessible($value): bool
361375 *
362376 * @return bool
363377 */
364- public static function exists ($ array , $ key ): bool
378+ public static function exists (ArrayAccess | array $ array , string | int $ key ): bool
365379 {
366380 if ($ array instanceof ArrayAccess) {
367381 return $ array ->offsetExists ($ key );
@@ -378,7 +392,7 @@ public static function exists($array, $key): bool
378392 *
379393 * @return bool
380394 */
381- public static function has ($ array , $ keys ): bool
395+ public static function has (ArrayAccess | array $ array , string | array $ keys ): bool
382396 {
383397 $ keys = (array )$ keys ;
384398
@@ -410,13 +424,13 @@ public static function has($array, $keys): bool
410424 *
411425 * If no key is given to the method, the entire array will be replaced.
412426 *
413- * @param ? array $array
427+ * @param array|ArrayObject|null $array
414428 * @param string $key
415429 * @param mixed $value
416430 *
417- * @return array|null
431+ * @return array|ArrayObject| null
418432 */
419- public static function set (&$ array , string $ key , $ value ): ? array
433+ public static function set (array | ArrayObject | null &$ array , string $ key , mixed $ value ): array | ArrayObject | null
420434 {
421435 if ($ array === null ) {
422436 return $ array ;
@@ -442,12 +456,12 @@ public static function set(&$array, string $key, $value): ?array
442456 /**
443457 * Remove one or many array items from a given array using "dot" notation.
444458 *
445- * @param array $array
459+ * @param array|ArrayObject $array
446460 * @param array|string $keys
447461 *
448462 * @return void
449463 */
450- public static function remove (&$ array , $ keys ): void
464+ public static function remove (array | ArrayObject &$ array , array | string $ keys ): void
451465 {
452466 $ original = &$ array ;
453467 $ keys = (array )$ keys ;
@@ -497,7 +511,7 @@ public static function replaceByTemplate(array $array, array $replace): array
497511 {
498512 $ res = [];
499513 foreach ($ array as $ key => $ item ) {
500- $ res [$ key ] = static ::itemReplaceByTemplate ($ item , $ replace );
514+ $ res [$ key ] = self ::itemReplaceByTemplate ($ item , $ replace );
501515 }
502516 return $ res ;
503517 }
0 commit comments