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

Serializable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 3
dl 0
loc 15
rs 10
c 2
b 0
f 0

2 Methods

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