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

DataTransformer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 6
c 2
b 0
f 2
lcom 1
cbo 2
dl 14
loc 77
ccs 23
cts 23
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getMapsManager() 0 4 1
A __construct() 0 6 1
A getConverter() 0 4 1
A getData() 7 7 1
A fillModel() 7 7 1
A createModel() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}