ConverterStep   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A add() 0 6 1
A process() 0 8 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