IntersectionMutator::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 8
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 IntersectionMutator extends Mutator
9
{
10
    /**
11
     * Intersects two collections.
12
     *
13
     * @param Collection $collection
14
     * @param \Iterator  $values
15
     * @return Collection
16
     */
17 1
    public function __invoke($collection, $values)
18
    {
19 1
        $collection = clone $collection;
20
21 1
        if (!is_array($values)) {
22 1
            $values = iterator_to_array($values);
23
        }
24
25 1
        $collection->exchangeArray(array_intersect(
26 1
            $collection->getArrayCopy(),
27
            $values
28
        ));
29
30 1
        return $collection;
31
    }
32
}
33