| Total Complexity | 8 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Coverage | 66.67% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class H |
||
| 12 | { |
||
| 13 | 5 | public static function array_first($array, callable $callback = null, $default = null) |
|
| 14 | { |
||
| 15 | 5 | if (is_null($callback)) { |
|
| 16 | if (empty($array)) { |
||
| 17 | return static::value($default); |
||
| 18 | } |
||
| 19 | foreach ($array as $item) { |
||
| 20 | return $item; |
||
| 21 | } |
||
| 22 | } |
||
| 23 | 5 | foreach ($array as $key => $value) { |
|
| 24 | 5 | if (call_user_func($callback, $value, $key)) { |
|
| 25 | 5 | return $value; |
|
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | 2 | return static::value($default); |
|
| 30 | } |
||
| 31 | |||
| 32 | 2 | public static function value($value) |
|
| 35 | } |
||
| 36 | } |
||
| 37 |