iterable_average()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 1
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved;
6
7
/**
8
 * Return the arithmetic mean.
9
 * If no elements are present, the result is NAN.
10
 *
11
 * @param iterable $iterable
12
 * @return float
13
 */
14
function iterable_average(iterable $iterable): float
0 ignored issues
show
introduced by
Function Improved\iterable_average() has parameter $iterable with no value type specified in iterable type iterable.
Loading history...
15
{
16 13
    $count = 0;
17 13
    $sum = 0;
18
19 13
    foreach ($iterable as $item) {
20 12
        $count++;
21 12
        $sum += $item;
22
    }
23
24 13
    return $count == 0 ? \NAN : ($sum / $count);
25
}
26