Issues (10)

Labels
Severity
1
<?php
2
3
namespace BaoPham\DynamoDb;
4
5
/**
6
 * Class H
7
 *
8
 * Short for "Helper".
9
 * We often get breaking changes from Laravel Helpers, so to ensure this won't happen again, we port the helpers here.
10
 *
11
 * @package BaoPham\DynamoDb
12
 */
13
// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
14
class H
15
{
16 80
    public static function array_first($array, callable $callback = null, $default = null)
17
    {
18 80
        if (is_null($callback)) {
19 2
            if (empty($array)) {
20
                return static::value($default);
21
            }
22 2
            foreach ($array as $item) {
23 2
                return $item;
24
            }
25
        }
26 78
        foreach ($array as $key => $value) {
27 78
            if (call_user_func($callback, $value, $key)) {
0 ignored issues
show
It seems like $callback can also be of type null; however, parameter $callback of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
            if (call_user_func(/** @scrutinizer ignore-type */ $callback, $value, $key)) {
Loading history...
28 78
                return $value;
29
            }
30
        }
31 60
        return static::value($default);
32
    }
33
34 60
    public static function value($value)
35
    {
36 60
        return $value instanceof \Closure ? $value() : $value;
37
    }
38
}
39
// phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
40