EntityHydrator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 22
ccs 9
cts 10
cp 0.9
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 15 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