InvokeMutator::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Underscore\Mutator;
4
5
use Underscore\Collection;
6
use Underscore\Mutator;
7
8
class InvokeMutator extends Mutator
9
{
10
    /**
11
     * Call $iterator for each element
12
     *
13
     * $iterator = function($value, $key, $collection)
14
     *
15
     * @param Collection $collection
16
     * @param callable   $iterator
17
     * @return Collection
18
     */
19 1
    public function __invoke($collection, $iterator)
20
    {
21 1
        $collection = clone $collection;
22 1
        foreach ($collection as $k => $v) {
23 1
            call_user_func($iterator, $v, $k, $collection);
24
        }
25
26 1
        return $collection;
27
    }
28
}
29