Hydrator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 42
ccs 15
cts 15
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A dehydrate() 0 8 1
A hydrate() 0 8 1
1
<?php
2
3
namespace Ronanchilvers\Orm\Model;
4
5
use Ronanchilvers\Orm\Model;
6
7
/**
8
 * Hydrator for models
9
 *
10
 * @todo Fix this so that it can pass unit tests
11
 * @author Ronan Chilvers <[email protected]>
12
 */
13
class Hydrator
14
{
15
    /**
16
     * Class constructor
17
     *
18
     * @author Ronan Chilvers <[email protected]>
19
     */
20 2
    public function __construct()
21 2
    {}
22
23
    /**
24
     * Hydrate a model from an array
25
     *
26
     * @param array $data
27
     * @param \Ronanchilvers\Orm\Model $model
28
     * @author Ronan Chilvers <[email protected]>
29
     */
30 1
    public function hydrate(array $array, Model $model)
31
    {
32 1
        $closure = function($data) {
33 1
            $this->data = $data;
34 1
            $this->afterLoad();
35 1
        };
36 1
        $hydrator = $closure->bindTo($model, $model);
37 1
        $hydrator($array);
38
    }
39
40
    /**
41
     * Dehydrate a model to an array
42
     *
43
     * @param \Ronanchilvers\Orm\Model $model
44
     * @return array
45
     * @author Ronan Chilvers <[email protected]>
46
     */
47 1
    public function dehydrate(Model $model)
48
    {
49 1
        $closure = function() {
50 1
            return $this->data;
51 1
        };
52 1
        $dehydrator = $closure->bindTo($model, $model);
53
54 1
        return $dehydrator();
55
    }
56
}
57