FilterDataOperation::processData()   A
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
rs 9.6111
1
<?php
2
3
namespace Oliverde8\Component\PhpEtl\ChainOperation\Transformer;
4
5
use Oliverde8\Component\PhpEtl\ChainOperation\AbstractChainOperation;
6
use Oliverde8\Component\PhpEtl\ChainOperation\DataChainOperationInterface;
7
use Oliverde8\Component\PhpEtl\Item\ChainBreakItem;
8
use Oliverde8\Component\PhpEtl\Item\DataItemInterface;
9
use Oliverde8\Component\PhpEtl\Item\ItemInterface;
10
use Oliverde8\Component\PhpEtl\Model\ExecutionContext;
11
use Oliverde8\Component\RuleEngine\RuleApplier;
12
13
class FilterDataOperation extends AbstractChainOperation implements DataChainOperationInterface
14
{
15
    protected RuleApplier $ruleApplier;
16
17
    protected array $rule;
18
19
    protected bool $negate;
20
21
    public function __construct(RuleApplier $ruleApplier, array $rule, bool $negate)
22
    {
23
        $this->ruleApplier = $ruleApplier;
24
        $this->rule = $rule;
25
        $this->negate = $negate;
26
    }
27
28
29
    public function processData(DataItemInterface $item, ExecutionContext $context): ItemInterface
30
    {
31
        $data = $item->getData();
32
33
        $resultData = [];
34
        $result = $this->ruleApplier->apply($data, $resultData, $this->rule);
35
36
        if (($this->negate && $result == false) || (!$this->negate && $result == true)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $result of type null|string against false; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
37
            return $item;
38
        }
39
40
        return new ChainBreakItem();
41
    }
42
}