Completed
Push — master ( bd8043...d919b4 )
by Francesco
05:20
created

HydratableTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 8 1
A toArray() 0 4 1
A getHydrator() 0 10 1
1
<?php
2
3
namespace Audiens\AppnexusClient\entity;
4
5
use GeneratedHydrator\Configuration;
6
use Zend\Hydrator\ObjectProperty;
7
8
/**
9
 * Class HydratableTrait
10
 */
11
trait HydratableTrait
12
{
13
    /**
14
     * @param array $objectArray
15
     *
16
     * @return self
17
     */
18
    public static function fromArray(array $objectArray)
19
    {
20
21
        $object = new self();
22
        self::getHydrator()->hydrate($objectArray, $object);
23
24
        return $object;
25
    }
26
27
    /**
28
     * @return array
29
     */
30
    public function toArray()
31
    {
32
        return self::getHydrator()->extract($this);
33
    }
34
35
    /**
36
     * @return ObjectProperty
37
     */
38
    private static function getHydrator()
39
    {
40
41
        $config = new Configuration(self::class);
42
        $hydratorClass = $config->createFactory()->getHydratorClass();
43
        $hydrator = new $hydratorClass();
44
45
        return $hydrator;
46
47
    }
48
}
49