Completed
Push — master ( 81b08b...26c086 )
by Alexpts
50:33
created

DataTransformer::getConverter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace PTS\DataTransformer;
3
4
use Symfony\Component\Yaml\Exception\ParseException;
5
6
class DataTransformer implements DataTransformerInterface
7
{
8
    /** @var ModelClosure */
9
    protected $closuresFn;
10
    /** @var TypeConverter */
11
    protected $typeConverter;
12
    /** @var MapsManager */
13
    protected $mapsManager;
14
15
    /**
16
     * @param TypeConverter $converter
17
     * @param MapsManager $mapsManager
18
     * @param ModelClosure $closuresFn
19
     */
20 6
    public function __construct(TypeConverter $converter, MapsManager $mapsManager, ModelClosure $closuresFn)
21
    {
22 6
        $this->mapsManager = $mapsManager;
23 6
        $this->typeConverter = $converter;
24 6
        $this->closuresFn = $closuresFn;
25 6
    }
26
27
    /**
28
     * @return MapsManager
29
     */
30 5
    public function getMapsManager()
31
    {
32 5
        return $this->mapsManager;
33
    }
34
35
    /**
36
     * @return TypeConverter
37
     */
38 1
    public function getConverter()
39
    {
40 1
        return $this->typeConverter;
41
    }
42
43
    /**
44
     * @param ModelInterface $model
45
     * @param string $mapType
46
     * @return array
47
     *
48
     * @throws ParseException
49
     */
50 2 View Code Duplication
    public function getData(ModelInterface $model, $mapType = 'dto')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52 2
        $class = get_class($model);
53 2
        $fn = \Closure::bind($this->closuresFn->getToDataFn(), $model, $class);
54 2
        $map = $this->mapsManager->getMap($class, $mapType);
55 2
        return $fn($map, $this->typeConverter);
56
    }
57
58
    /**
59
     * @param array $data
60
     * @param ModelInterface $model
61
     * @param string $mapType
62
     *
63
     * @throws ParseException
64
     */
65 2 View Code Duplication
    public function fillModel(array $data, ModelInterface $model, $mapType = 'dto')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67 2
        $class = get_class($model);
68 2
        $fn = \Closure::bind($this->closuresFn->getFillFn(), $model, $class);
69 2
        $map = $this->mapsManager->getMap($class, $mapType);
70 2
        $fn($data, $map, $this->typeConverter);
71 2
    }
72
73
    /**
74
     * @param string $class
75
     * @return ModelInterface
76
     */
77 2
    public function createModel($class)
78
    {
79 2
        $emptyModel = new \ReflectionClass($class);
80 2
        return $emptyModel->newInstanceWithoutConstructor();
81
    }
82
}