PropertyTransformer::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
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