| Conditions | 8 |
| Paths | 10 |
| Total Lines | 17 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 8 |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | function iterable_min(iterable $iterable, callable $compare = null) |
||
|
|
|||
| 15 | { |
||
| 16 | 32 | $first = true; |
|
| 17 | 32 | $min = null; |
|
| 18 | |||
| 19 | 32 | if (!isset($compare)) { |
|
| 20 | 25 | foreach ($iterable as $value) { |
|
| 21 | 24 | $min = (!isset($min) || $value < $min) ? $value : $min; |
|
| 22 | } |
||
| 23 | } else { |
||
| 24 | 7 | foreach ($iterable as $value) { |
|
| 25 | 7 | $min = ($first || call_user_func($compare, $min, $value) > 0) ? $value : $min; |
|
| 26 | 7 | $first = false; |
|
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | 32 | return $min; |
|
| 31 | } |
||
| 32 |