GroupByMutator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 21
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\Mutator;
4
5
use Underscore\Collection;
6
use Underscore\Mutator;
7
8
class GroupByMutator extends Mutator
9
{
10
    /**
11
     * Creates an object composed of keys generated from the results
12
     * of running each element of a collection through the callback
13
     *
14
     * @param Collection $collection
15
     * @param callable   $iterator
16
     * @return Collection
17
     */
18 3
    public function __invoke($collection, $iterator)
19
    {
20 3
        $newCollection = [];
21
22 3
        foreach ($collection as $value) {
23 2
            $newCollection[call_user_func($iterator, $value)][] = $value;
24
        }
25
26 3
        return $this->copyCollectionWith($collection, $newCollection);
27
    }
28
}
29