Passed
Push — main ( c2020d...c060b3 )
by Gabriel
13:36
created

ArrayObject::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
dl 0
loc 3
rs 10
c 1
b 0
f 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace ByTIC\DataObjects\Casts;
4
5
use ArrayObject as BaseArrayObject;
6
use JsonSerializable;
7
use Serializable;
8
9
/**
10
 * Class ArrayObject
11
 * @package ByTIC\DataObjects\Casts
12
 */
13
class ArrayObject extends BaseArrayObject implements JsonSerializable, Serializable
14
{
15
    /**
16
     * Get the instance as an array.
17
     *
18
     * @return array
19
     */
20
    public function toArray()
21
    {
22
        return $this->getArrayCopy();
23
    }
24
25
    /**
26
     * @inheritDoc
27
     */
28
    public function serialize()
29
    {
30
        return serialize($this->toArray());
31
    }
32
33
    /**
34
     * Constructs the object.
35
     * @link https://php.net/manual/en/serializable.unserialize.php
36
     * @param string $serialized The string representation of the object.
37
     * @return void
38
     */
39
    public function unserialize($data)
40
    {
41
        $data = @unserialize($data);
42
        if (!is_array($data)) {
43
            return;
44
        }
45
        foreach ($data as $property => $value) {
46
            $this[$property] = $value;
47
        }
48
    }
49
50
    /**
51
     * Get the array that should be JSON serialized.
52
     *
53
     * @return array
54
     */
55
    public function jsonSerialize()
56
    {
57
        return $this->getArrayCopy();
58
    }
59
}
60