ValueConverterStep   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 6 1
A process() 0 14 3
1
<?php
2
3
namespace Port\Steps\Step;
4
5
use Port\Steps\Step;
6
use Symfony\Component\PropertyAccess\PropertyAccessor;
7
8
/**
9
 * @author Markus Bachmann <[email protected]>
10
 */
11
class ValueConverterStep implements Step
12
{
13
    /**
14
     * @var array
15
     */
16
    private $converters = [];
17
18
    /**
19
     * @param string   $property
20
     * @param callable $converter
21
     *
22
     * @return $this
23
     */
24 1
    public function add($property, callable $converter)
25
    {
26 1
        $this->converters[$property][] = $converter;
27
28 1
        return $this;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    public function process($item, callable $next)
35
    {
36 1
        $accessor = new PropertyAccessor();
37
38 1
        foreach ($this->converters as $property => $converters) {
39 1
            foreach ($converters as $converter) {
40 1
                $orgValue = $accessor->getValue($item, $property);
41 1
                $value = call_user_func($converter, $orgValue);
42 1
                $accessor->setValue($item, $property, $value);
43 1
            }
44 1
        }
45
46 1
        return $next($item);
47
    }
48
}
49