WhereMutator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 17 7
1
<?php
2
3
namespace Underscore\Mutator;
4
5
use Underscore\Collection;
6
use Underscore\Mutator;
7
8
class WhereMutator extends Mutator
9
{
10
    /**
11
     * Remove all values that do not match the given key-value pairs.
12
     *
13
     * By default strict comparison is used.
14
     *
15
     * @param Collection $collection
16
     * @param array      $properties
17
     * @param boolean    $strict
18
     * @return Collection
19
     */
20 1
    public function __invoke($collection, array $properties, $strict = true)
21
    {
22 1
        $filter = new FilterMutator;
23
24 1
        return $filter($collection, function ($item) use ($properties, $strict) {
25 1
            foreach ($properties as $key => $value) {
26 1
                if (empty($item[$key])
27 1
                    || ($strict && $item[$key] !== $value)
28 1
                    || (!$strict && $item[$key] != $value)
29
                ) {
30 1
                    return false;
31
                }
32
            }
33
34 1
            return true;
35 1
        });
36
    }
37
}
38