Passed
Push — master ( aa67e9...f960a1 )
by De Cramer
02:31
created

ChainSplitOperation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Oliverde8\Component\PhpEtl\ChainOperation;
4
5
use Oliverde8\Component\PhpEtl\ChainProcessor;
6
use Oliverde8\Component\PhpEtl\Item\DataItemInterface;
7
use Oliverde8\Component\PhpEtl\Item\ItemInterface;
8
use Oliverde8\Component\PhpEtl\Item\StopItem;
9
10
/**
11
 * Class ChainSplitOperation
12
 *
13
 * @author    de Cramer Oliver<[email protected]>
14
 * @copyright 2018 Oliverde8
15
 * @package Oliverde8\Component\PhpEtl\ChainOperation
16
 */
17
class ChainSplitOperation extends AbstractChainOperation implements DataChainOperationInterface
18
{
19
    /** @var ChainProcessor[] */
20
    protected $chainProcessors;
21
22
    /**
23
     * ChainSplitOperation constructor.
24
     *
25
     * @param ChainProcessor[] $chainProcessors
26
     */
27 2
    public function __construct(array $chainProcessors)
28
    {
29 2
        $this->chainProcessors = $chainProcessors;
30 2
    }
31
32
    /**
33
     * Process DataItems.
34
     *
35
     * @param DataItemInterface $item
36
     * @param array $context
37
     *
38
     * @return ItemInterface
39
     * @throws \Oliverde8\Component\PhpEtl\Exception\ChainOperationException
40
     */
41 2
    public function processData(DataItemInterface $item, array &$context)
42
    {
43 2
        foreach ($this->chainProcessors as $chainProcessor) {
44 2
            $chainProcessor->processItem($item, 0,  $context);
45
        }
46
47
        // Nothing to process.
48 2
        return $item;
49
    }
50
51
    /**
52
     * @param StopItem $item
53
     * @param array $context
54
     *
55
     * @return StopItem
56
     * @throws \Oliverde8\Component\PhpEtl\Exception\ChainOperationException
57
     */
58 1
    public function processStop(StopItem $item, array &$context)
59
    {
60 1
        foreach ($this->chainProcessors as $chainProcessor) {
61 1
            $result = $chainProcessor->processItem($item, 0,  $context);
62
63 1
            if ($result !== $item) {
64
                // Return a new stop item in order to continue flushing out data with stop items.
65 1
                $item = new StopItem();
66
            }
67
        }
68
69 1
        return $item;
70
    }
71
}
72