ConverterStep::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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