Completed
Push — master ( 8a83ac...f28038 )
by Gabriel
04:28
created

SerializableRecord::__sleep()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Nip\Records\Traits\Serializable;
4
5
/**
6
 * Trait SerializableRecord
7
 * @package Nip\Records\Traits\Serializable
8
 */
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()
47
    {
48
    }
49
}