ReduceRightAccessor::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Underscore\Accessor;
4
5
use Underscore\Accessor;
6
use Underscore\Collection;
7
8
class ReduceRightAccessor extends Accessor
9
{
10
    /**
11
     * Reduces collection to single value using $iterator. Reversed direction.
12
     *
13
     * $iterator = function($accumulator, $value)
14
     *
15
     * @param Collection $collection
16
     * @param callable   $iterator
17
     * @param mixed      $initial
18
     * @return Collection
19
     */
20 1
    public function __invoke($collection, $iterator, $initial = null)
21
    {
22 1
        $collection = clone $collection;
23
24 1
        foreach ($collection->getIteratorReversed() as $value) {
25 1
            $initial = call_user_func($iterator, $initial, $value);
26
        }
27
28 1
        return $initial;
29
    }
30
}
31