Passed
Push — 7.x ( bb6d27...92b4bd )
by Adrien
08:18
created

SplTypeTrait::jsonSerialize()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Part of SplTypes package.
5
 *
6
 * (c) Adrien Loyant <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ducks\Component\SplTypes;
13
14
/**
15
 * Trait used for magic
16
 *
17
 * @psalm-api
18
 */
19
trait SplTypeTrait
20
{
21
    /**
22
     * Internal enum value.
23
     *
24
     * @var mixed
25
     */
26
    // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
27
    protected $__default;
28
29
    /**
30
     * Specify data which should be serialized to JSON.
31
     *
32
     * @return mixed
33
     */
34 5
    public function jsonSerialize()
35
    {
36 5
        return $this->__default;
37
    }
38
39
    /**
40
     * Serialize object.
41
     *
42
     * @return array<string,mixed>
43
     */
44 5
    final public function __serialize(): array
45
    {
46 5
        return [
47 5
            '__default' => $this->__default,
48 5
        ];
49
    }
50
51
    /**
52
     * Unserialize object.
53
     *
54
     * @param array<string,mixed> $data
55
     * @return void
56
     */
57 5
    final public function __unserialize(array $data): void
58
    {
59 5
        $this->__default = $data['__default'];
60
    }
61
62
    /**
63
     * Stringify object.
64
     *
65
     * @return string
66
     */
67 1
    final public function __toString(): string
68
    {
69 1
        return (string) $this->__default;
70
    }
71
72
    /**
73
     * Export object.
74
     *
75
     * @param array<mixed,mixed> $properties
76
     *
77
     * @return SplType
78
     *
79
     * @codeCoverageIgnore
80
     * @psalm-suppress UnsafeInstantiation
81
     */
82
    final public static function __set_state(array $properties): object
83
    {
84
        return /** @scrutinizer ignore-call */ new static($properties['__default']);
85
    }
86
87
    /**
88
     * Dumping object.
89
     *
90
     * @return array<string,mixed>
91
     *
92
     * @codeCoverageIgnore
93
     */
94
    final public function __debugInfo(): array
95
    {
96
        return [
97
            '__default' => $this->__default,
98
        ];
99
    }
100
}
101