UniqMutator::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Underscore\Mutator;
4
5
use Underscore\Collection;
6
use Underscore\Mutator;
7
8
class UniqMutator extends Mutator
9
{
10
    /**
11
     * Removes duplicate items from the collection.
12
     *
13
     * @param Collection $collection
14
     * @return Collection
15
     */
16 3
    public function __invoke($collection)
17
    {
18 3
        $seen = [];
19 3
        foreach ($collection as $k => $v) {
20 3
            if (!in_array($v, $seen, true)) {
21 3
                $seen[$k] = $v;
22
            }
23
        }
24
25 3
        return $this->copyCollectionWith($collection, $seen);
26
    }
27
}
28