iterable_reduce()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved;
6
7
/**
8
 * Reduce all elements to a single value using a callback.
9
 *
10
 * @param iterable  $iterable
11
 * @param callable  $callback
12
 * @param mixed     $initial
13
 * @return mixed
14
 */
15
function iterable_reduce(iterable $iterable, callable $callback, $initial = null)
0 ignored issues
show
introduced by
Function Improved\iterable_reduce() has parameter $iterable with no value type specified in iterable type iterable.
Loading history...
16
{
17 11
    $result = $initial;
18
19 11
    foreach ($iterable as $key => $value) {
20 10
        $result = call_user_func($callback, $result, $value, $key);
21
    }
22
23 11
    return $result;
24
}
25