FilterTrait::applyFilter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RulerZ\Executor\ArrayTarget;
6
7
use RulerZ\Context\ExecutionContext;
8
use RulerZ\Context\ObjectContext;
9
use RulerZ\Result\IteratorTools;
10
11
trait FilterTrait
12
{
13
    abstract protected function execute($target, array $operators, array $parameters);
14
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function applyFilter($target, array $parameters, array $operators, ExecutionContext $context)
0 ignored issues
show
Unused Code introduced by
The parameter $target is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $operators is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
    {
20
        throw new \LogicException('Not supported.');
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function filter($target, array $parameters, array $operators, ExecutionContext $context)
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
    {
28
        return IteratorTools::fromGenerator(function () use ($target, $parameters, $operators) {
29
            foreach ($target as $row) {
30
                $targetRow = is_array($row) ? $row : new ObjectContext($row);
31
32
                if ($this->execute($targetRow, $operators, $parameters)) {
33
                    yield $row;
34
                }
35
            }
36
        });
37
    }
38
}
39