Completed
Push — master ( 0f5459...b9fce4 )
by Max
01:22
created

HydratableTrait::dehydrate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 *  @copyright (c) 2019 Mendel <[email protected]>
5
 *  @license see license.txt
6
 */
7
8
namespace drycart\data;
9
10
/**
11
 *
12
 * @author mendel
13
 */
14
trait HydratableTrait
15
{
16
    /**
17
     * Hydrate
18
     * @param array $data
19
     * @return void
20
     */
21
    public function hydrate(array $data) : void
22
    {
23
        foreach($data as $key=>$value) {
24
            $this->$key = $value;
25
        }
26
    }
27
28
    public function dehydrate(): array
29
    {
30
        $data = [];
31
        foreach(GetterHelper::getKeys($this) as $key) {
32
            $data[$key] = $this->$key;
33
        }
34
        return $data;
35
    }
36
}
37