Completed
Push — master ( 411d94...8fae9a )
by John
02:59
created

EntityHydrator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0
ccs 9
cts 10
cp 0.9

1 Method

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 16 3
1
<?php
2
/**
3
 * This file is part of graze/unicontroller-client.
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/unicontroller-client/blob/master/LICENSE.md
11
 * @link https://github.com/graze/unicontroller-client
12
 */
13
namespace Graze\UnicontrollerClient\Entity;
14
15
use Graze\UnicontrollerClient\Entity\Entity\EntityInterface;
16
17
class EntityHydrator
18
{
19
    /**
20
     * @param EntityInterface $entity
21
     * @param array $data
22
     * @return EntityInterface
23
     */
24
    public function hydrate(EntityInterface $entity, array $data)
25
    {
26 20
        $hydrator = function ($data) {
27 20
            foreach ($data as $property => $value) {
28 20
                if (!property_exists($this, $property)) {
29
                    continue;
30
                }
31 20
                $this->$property = $value;
32 20
            }
33 20
        };
34
35 20
        $hydrator = $hydrator->bindTo($entity, $entity);
36 20
        $hydrator($data);
37
38 20
        return $entity;
39
    }
40
}
41