Completed
Push — develop ( 515643...e2e58e )
by
unknown
08:08
created

MappingEntityHydrator::extract()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Entity\Hydrator;
12
13
use Core\Entity\EntityInterface;
14
15
/**
16
 * ${CARET}
17
 * 
18
 * @author Mathias Gelhausen <[email protected]>
19
 * @todo write test 
20
 */
21
class MappingEntityHydrator extends EntityHydrator
22
{
23
    protected $map = [];
24
25
    public function __construct(array $map = [])
26
    {
27
        $this->setPropertyMap($map);
28
29
        parent::__construct();
30
    }
31
32
    public function setPropertyMap(array $map)
33
    {
34
        $this->map = $map;
35
36
        return $this;
37
    }
38
39
    public function getPropertyMap()
40
    {
41
        return $this->map;
42
    }
43
44 View Code Duplication
    public function extract($object)
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...
45
    {
46
47
        $data = parent::extract($object);
48
49
        foreach ($this->map as $from => $to) {
50
            if (array_key_exists($from, $data)) {
51
                $data[$to] = $this->extractValue($to, $data[$from], $object);
52
                unset($data[$from]);
53
            }
54
        }
55
56
        return $data;
57
    }
58
59 View Code Duplication
    public function hydrate(array $data, $object)
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...
60
    {
61
        foreach ($this->map as $to => $from) {
62
            if (array_key_exists($from, $data)) {
63
                $data[$to] = $this->hydrateValue($from, $data[$from], $data);
64
                unset($data[$from]);
65
            }
66
        }
67
68
        return parent::hydrate($data, $object);
69
    }
70
}