ConverterStep::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
ccs 5
cts 5
cp 1
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Ddeboer\DataImport\Step;
4
5
use Ddeboer\DataImport\Step;
6
use Ddeboer\DataImport\Exception\UnexpectedTypeException;
7
8
/**
9
 * @author Markus Bachmann <[email protected]>
10
 */
11
class ConverterStep implements Step
12
{
13
    /**
14
     * @var callable[]
15
     */
16
    private $converters;
17
18
    /**
19
     * @param array $converters
20
     */
21 4
    public function __construct(array $converters = [])
22
    {
23 4
        foreach ($converters as $converter) {
24 1
            $this->add($converter);
25 4
        }
26 4
    }
27
28
    /**
29
     * @param callable $converter
30
     *
31
     * @return $this
32
     */
33 4
    public function add(callable $converter)
34
    {
35 4
        $this->converters[] = $converter;
36
37 4
        return $this;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 4
    public function process(&$item)
44
    {
45 4
        foreach ($this->converters as $converter) {
46 4
            $item = call_user_func($converter, $item);
47 4
        }
48
49 4
        return true;
50
    }
51
}
52