FilterOutputData::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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