Completed
Push — master ( a8d311...9dd330 )
by Woody
04:06 queued 02:09
created

IntersectionMutator::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 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
    public function __invoke($collection, $values)
18
    {
19
        $collection = clone $collection;
20
21
        if (!is_array($values)) {
22
            $values = iterator_to_array($values);
23
        }
24
25
        $collection->exchangeArray(array_intersect(
26
            $collection->getArrayCopy(),
27
            $values
28
        ));
29
30
        return $collection;
31
    }
32
}
33