AttributeModel::__toString()   A
last analyzed

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
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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
}