Conditions | 4 |
Paths | 5 |
Total Lines | 20 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
24 | 15 | public function apply(\Iterator $set) |
|
25 | { |
||
26 | /** @var mixed[] $data */ |
||
27 | 15 | $data = array_values(iterator_to_array($set)); |
|
28 | 15 | $count = count($data); |
|
29 | |||
30 | 15 | if ($count === 0) { |
|
31 | 1 | return 0; |
|
32 | } |
||
33 | |||
34 | 14 | sort($data); |
|
35 | |||
36 | 14 | $middle = (($count + 1) / 2) - 1; |
|
37 | 14 | $left = (int) floor($middle); |
|
38 | 14 | $right = (int) ceil($middle); |
|
39 | |||
40 | 14 | $leftVal = $data[$left]; |
|
41 | 14 | $rightVal = $data[$right]; |
|
42 | |||
43 | 14 | return is_scalar($leftVal) && is_scalar($rightVal) ? ($data[$left] + $data[$right]) / 2 : 0; |
|
44 | } |
||
46 |