ConvertsToArray::toArray()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arcanedev\LaravelMetrics\Concerns;
6
7
/**
8
 * Trait     ConvertsToArray
9
 *
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
trait ConvertsToArray
13
{
14
    /* -----------------------------------------------------------------
15
     |  Main Methods
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * Get the instance as an array.
21
     *
22
     * @return array
23
     */
24
    abstract public function toArray(): array;
25
26
    /**
27
     * Convert the object to its JSON representation.
28
     *
29
     * @param  int  $options
30
     *
31
     * @return string
32
     */
33 24
    public function toJson($options = 0): string
34
    {
35 24
        return json_encode($this->jsonSerialize(), $options);
36
    }
37
38
    /**
39
     * Get the instance as an array to be serialized to JSON.
40
     *
41
     * @return array
42
     */
43 24
    public function jsonSerialize(): array
44
    {
45 24
        return $this->toArray();
46
    }
47
}
48