PropertyTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A transform() 0 16 2
1
<?php
2
3
namespace Extraload\Transformer;
4
5
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
6
7
class PropertyTransformer implements TransformerInterface
8
{
9
    private $transformer;
10
    private $propertyAccessor;
11
    private $path;
12
13
    public function __construct(
14
        TransformerInterface $transformer,
15
        PropertyAccessorInterface $propertyAccessor,
16
        $path
17
    ) {
18
        $this->transformer = $transformer;
19
        $this->propertyAccessor = $propertyAccessor;
20
        $this->path = $path;
21
    }
22
23
    public function transform($data)
24
    {
25
        if (null === $data) {
26
            return;
27
        }
28
29
        $this->propertyAccessor->setValue(
30
            $data,
31
            $this->path,
32
            $this->transformer->transform(
33
                $this->propertyAccessor->getValue($data, $this->path)
34
            )
35
        );
36
37
        return $data;
38
    }
39
}
40