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

JsonSerializableTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 3
c 1
b 0
f 0
dl 0
loc 32
ccs 0
cts 4
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __debugInfo() 0 3 1
A jsonSerialize() 0 3 1
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