| Conditions | 6 |
| Paths | 8 |
| Total Lines | 17 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 6 |
| CRAP Score | 8.304 |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 | } |
||
| 37 |