ChainSplitOperation   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 37
rs 10
c 1
b 0
f 0
ccs 7
cts 7
cp 1
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A processStop() 0 12 3
A processData() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Oliverde8\Component\PhpEtl\ChainOperation;
6
7
use Oliverde8\Component\PhpEtl\ChainProcessor;
8
use Oliverde8\Component\PhpEtl\Item\DataItemInterface;
9
use Oliverde8\Component\PhpEtl\Item\ItemInterface;
10
use Oliverde8\Component\PhpEtl\Item\StopItem;
11
use Oliverde8\Component\PhpEtl\Model\ExecutionContext;
12
13
/**
14
 * Class ChainSplitOperation
15
 *
16
 * @author    de Cramer Oliver<[email protected]>
17
 * @copyright 2018 Oliverde8
18
 * @package Oliverde8\Component\PhpEtl\ChainOperation
19
 */
20
class ChainSplitOperation extends AbstractChainOperation implements DataChainOperationInterface
21
{
22
    /** @var ChainProcessor[] */
23
    protected array $chainProcessors;
24
25
    /**
26
     * ChainSplitOperation constructor.
27 2
     *
28
     * @param ChainProcessor[] $chainProcessors
29 2
     */
30 2
    public function __construct(array $chainProcessors)
31
    {
32
        $this->chainProcessors = $chainProcessors;
33
    }
34
35
    public function processData(DataItemInterface $item, ExecutionContext $context): ItemInterface
36
    {
37
        foreach ($this->chainProcessors as $chainProcessor) {
38
            $chainProcessor->processItemWithChain($item, 0,  $context);
39
        }
40
41 2
        // Nothing to process.
42
        return $item;
43 2
    }
44 2
45
    public function processStop(StopItem $item, ExecutionContext $context): ItemInterface
46
    {
47
        foreach ($this->chainProcessors as $chainProcessor) {
48 2
            $result = $chainProcessor->processItemWithChain($item, 0,  $context);
49
50
            if ($result !== $item) {
51
                // Return a new stop item in order to continue flushing out data with stop items.
52
                $item = new StopItem();
53
            }
54
        }
55
56
        return $item;
57
    }
58
}
59