Total Complexity | 7 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 87.5% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
9 | trait SerializableRecord |
||
10 | { |
||
11 | /** |
||
12 | * @return string |
||
13 | */ |
||
14 | 1 | public function serialize() |
|
15 | { |
||
16 | 1 | $properties = $this->__sleep(); |
|
17 | 1 | $data = []; |
|
18 | 1 | foreach ($properties as $property) { |
|
19 | 1 | $data[$property] = $this->{$property}; |
|
20 | } |
||
21 | 1 | return serialize($data); |
|
22 | } |
||
23 | |||
24 | /** |
||
25 | * @param $data |
||
26 | */ |
||
27 | 1 | public function unserialize($data) |
|
28 | { |
||
29 | 1 | $data = unserialize($data); |
|
30 | 1 | if (!is_array($data)) { |
|
31 | return; |
||
32 | } |
||
33 | 1 | foreach ($data as $property => $value) { |
|
34 | 1 | $this->{$property} = $value; |
|
35 | } |
||
36 | 1 | } |
|
37 | |||
38 | /** |
||
39 | * @return array |
||
40 | */ |
||
41 | 1 | public function __sleep() |
|
42 | { |
||
43 | 1 | return ['_data']; |
|
44 | } |
||
45 | |||
46 | public function __wakeup() |
||
48 | } |
||
49 | } |