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_max(iterable $iterable, callable $compare = null) |
||
|
|||
15 | { |
||
16 | 26 | $first = true; |
|
17 | 26 | $max = null; |
|
18 | |||
19 | 26 | if (!isset($compare)) { |
|
20 | 19 | foreach ($iterable as $value) { |
|
21 | 18 | $max = (!isset($max) || $value > $max) ? $value : $max; |
|
22 | } |
||
23 | } else { |
||
24 | 7 | foreach ($iterable as $value) { |
|
25 | 7 | $max = ($first || call_user_func($compare, $max, $value) < 0) ? $value : $max; |
|
26 | 7 | $first = false; |
|
27 | } |
||
28 | } |
||
29 | |||
30 | 26 | return $max; |
|
31 | } |
||
32 |