AverageOperation::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * File was created 07.05.2015 09:11
4
 *
5
 * @author Karsten J. Gerber <[email protected]>
6
 */
7
8
namespace PeekAndPoke\Component\Psi\Operation\Terminal;
9
10
use PeekAndPoke\Component\Psi\TerminalOperation;
11
12
/**
13
 * AverageOperation
14
 *
15
 * @author Karsten J. Gerber <[email protected]>
16
 */
17
class AverageOperation implements TerminalOperation
18
{
19
    /**
20
     * {@inheritdoc}
21
     *
22
     * @return float
23
     */
24 8
    public function apply(\Iterator $set)
25
    {
26 8
        $data = iterator_to_array($set);
27
28 8
        if (count($data) === 0) {
29 1
            return 0;
30
        }
31
32 7
        return array_sum($data) / count($data);
33
    }
34
}
35