iterable_sum()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
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 3
nop 1
dl 0
loc 13
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
 * Calculate the sum of all numbers.
9
 * If no elements are present, the result is 0.
10
 *
11
 * @param iterable $iterable
12
 * @return int|float
13
 */
14
function iterable_sum(iterable $iterable)
0 ignored issues
show
introduced by
Function Improved\iterable_sum() has parameter $iterable with no value type specified in iterable type iterable.
Loading history...
15
{
16 13
    if (is_array($iterable)) {
17 2
        return array_sum($iterable);
18
    }
19
20 11
    $sum = 0;
21
22 11
    foreach ($iterable as $item) {
23 10
        $sum += $item;
24
    }
25
26 11
    return $sum;
27
}
28