FilterOutputData   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A filter() 0 17 4
1
<?php
2
namespace Consolidation\Filter;
3
4
use Dflydev\DotAccessData\Data;
5
6
/**
7
 * Remove output result rows that do not match filter criteria.
8
 *
9
 * Only usable with nested arrays, e.g. as you might provide to RowsOfFields
10
 */
11
class FilterOutputData
12
{
13
    public function __construct()
14
    {
15
    }
16
17
    /**
18
     * Filter the provided data.
19
     */
20
    public function filter($data, OperatorInterface $op)
21
    {
22
        $result = [];
23
24
        foreach ($data as $id => $value) {
25
            $row = new Data($value);
26
            if (!isset($value['id'])) {
27
                $row->set('id', $id);
28
            }
29
30
            if ($op->test($row)) {
31
                $result[$id] = $value;
32
            }
33
        }
34
35
        return $result;
36
    }
37
}
38