DynamicModel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 40
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 3 1
A __construct() 0 2 1
A __toString() 0 3 1
A toArray() 0 10 2
1
<?php
2
namespace SimpleCMS\DynamicUnit\Packages;
3
4
use Illuminate\Support\Collection;
5
6
class DynamicModel implements \JsonSerializable
7
{
8
9
    public function __construct(public int $id, public string $name, public string $value, public null|Collection $items)
10
    {
11
    }
12
13
14
    /**
15
     * toArray
16
     * @return array<string,null|string>>
17
     */
18
    public function toArray(): array
19
    {
20
        $data = [
21
            'id' => $this->id ?? 0,
22
            'name' => $this->name ?? null,
23
            'value' => $this->value ?? null,
24
            'items' => $this->items ? $this->items->toArray() : null
25
        ];
26
27
        return $data;
28
    }
29
30
    /**
31
     * jsonSerialize
32
     * @return mixed
33
     */
34
    public function jsonSerialize()
35
    {
36
        return $this->toArray();
37
    }
38
39
    /**
40
     * __toString
41
     * @return string
42
     */
43
    public function __toString(): string
44
    {
45
        return json_encode($this->toArray());
46
    }
47
}