ReduceRightAccessor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 23
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 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