SplitterWorker::setStorageStack()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Transfer\Worker;
4
5
use Transfer\Storage\StorageStack;
6
use Transfer\Storage\StorageStackAwareInterface;
7
8
class SplitterWorker implements WorkerInterface, StorageStackAwareInterface
9
{
10
    /**
11
     * @var StorageStack Storage stack
12
     */
13
    protected $stack;
14
15
    /**
16
     * {@inheritdoc}
17
     */
18 3
    public function setStorageStack(StorageStack $stack)
19
    {
20 3
        $this->stack = $stack;
21 3
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 3
    public function handle($object)
27
    {
28 3
        if (!is_array($object)) {
29 1
            throw new \InvalidArgumentException(sprintf('Expected array for splitting, got %s', gettype($object)));
30
        }
31
32 2
        $storage = $this->stack->getScope('local');
33
34 2
        foreach ($object as $element) {
35 2
            $storage->add($element);
36 2
        }
37 2
    }
38
}
39