FilterDataOperation   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processData() 0 12 5
A __construct() 0 5 1
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
}