Completed
Push — master ( 45165d...5e44c4 )
by Alexey
04:08 queued 11s
created

JsonSerializableTrait::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nelexa\GPlay\Model;
6
7
/**
8
 * Trait JsonSerializableTrait.
9
 */
10
trait JsonSerializableTrait
11
{
12
    /**
13
     * Returns class properties as an array.
14
     *
15
     * @return array
16
     */
17
    abstract public function asArray(): array;
18
19
    /**
20
     * Specify data which should be serialized to JSON.
21
     *
22
     * Serializes the object to a value that can be serialized natively by `json_encode()`.
23
     *
24
     * @return mixed returns data which can be serialized by `json_encode()`,
25
     *               which is a value of any type other than a `resource`
26
     *
27
     * @see https://php.net/manual/en/jsonserializable.jsonserialize.php JsonSerializable::jsonSerialize
28
     */
29
    public function jsonSerialize()
30
    {
31
        return $this->asArray();
32
    }
33
34
    /**
35
     * @return array
36
     *
37
     * @internal
38
     */
39
    public function __debugInfo()
40
    {
41
        return $this->asArray();
42
    }
43
}
44