Hydrator::dehydrate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
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