Passed
Push — master ( c12bcb...001f10 )
by Caen
03:06 queued 11s
created

Serializable::toJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Support\Concerns;
6
7
/**
8
 * Automatically serializes an Arrayable interface when JSON is requested.
9
 *
10
 * @see \Hyde\Support\Contracts\SerializableContract
11
 * @see \Hyde\Framework\Testing\Unit\SerializableTest
12
 */
13
trait Serializable
14
{
15
    /** @inheritDoc */
16
    abstract public function toArray(): array;
17
18
    /** @inheritDoc */
19
    public function jsonSerialize(): array
20
    {
21
        return $this->toArray();
22
    }
23
24
    /** @inheritDoc */
25
    public function toJson($options = 0): string
26
    {
27
        return json_encode($this->jsonSerialize(), $options);
28
    }
29
}
30