Completed
Push — master ( b03e32...44190a )
by Sérgio
03:19
created

each.php ➔ each()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 14
nc 1
nop 0
dl 0
loc 25
ccs 13
cts 13
cp 1
crap 2
rs 8.8571
c 1
b 0
f 1
1
<?php
2
3
namespace Sergiors\Functional;
4
5
/**
6
 * @author Sérgio Rafael Siqueira <[email protected]>
7
 *
8
 * @return mixed
9
 */
10
function each()
11
{
12 3
    $args = func_get_args();
13
14
    $each = function (\Closure $fn, $ls) {
15 3
        if ($ls instanceof \Iterator) {
16
            iterator_apply($ls, function () use ($fn, $ls) {
17
                $args = [
18 1
                    $ls->current(),
19 1
                    $ls->key()
20 1
                ];
21
22 1
                call_user_func_array($fn, $args);
23 1
                return true;
24 1
            });
25
26 1
            return $ls;
27
        }
28
29 2
        array_walk($ls, $fn);
30 2
        return $ls;
31 3
    };
32
33 3
    return call_user_func_array(curry($each), $args);
34
}
35