AttributeModel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
eloc 12
c 2
b 0
f 1
dl 0
loc 44
rs 10

4 Methods

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