Completed
Branch master (ac66df)
by Саша
10:27 queued 47s
created

PropertyTransformer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 30
rs 10

2 Methods

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