Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
18 / 18 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Tag | |
100.00% |
18 / 18 |
|
100.00% |
6 / 6 |
10 | |
100.00% |
1 / 1 |
getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getL11n | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
setL11n | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
toArray | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
jsonSerialize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package Modules\Tag\Models |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace Modules\Tag\Models; |
16 | |
17 | use Modules\Admin\Models\Account; |
18 | use phpOMS\Localization\BaseStringL11n; |
19 | use phpOMS\Localization\ISO639x1Enum; |
20 | |
21 | /** |
22 | * Tag class. |
23 | * |
24 | * @package Modules\Tag\Models |
25 | * @license OMS License 2.0 |
26 | * @link https://jingga.app |
27 | * @since 1.0.0 |
28 | */ |
29 | class Tag implements \JsonSerializable |
30 | { |
31 | /** |
32 | * Article ID. |
33 | * |
34 | * @var int |
35 | * @since 1.0.0 |
36 | */ |
37 | public int $id = 0; |
38 | |
39 | /** |
40 | * Title. |
41 | * |
42 | * @var string|BaseStringL11n |
43 | * @since 1.0.0 |
44 | */ |
45 | public string | BaseStringL11n $title = ''; |
46 | |
47 | /** |
48 | * Color RGBA. |
49 | * |
50 | * @var string |
51 | * @since 1.0.0 |
52 | */ |
53 | public string $color = '00000000'; |
54 | |
55 | /** |
56 | * Icon. |
57 | * |
58 | * @var string |
59 | * @since 1.0.0 |
60 | */ |
61 | public string $icon = ''; |
62 | |
63 | /** |
64 | * Creator. |
65 | * |
66 | * @var null|Account |
67 | * @since 1.0.0 |
68 | */ |
69 | public ?Account $owner = null; |
70 | |
71 | /** |
72 | * Tag type. |
73 | * |
74 | * @var int |
75 | * @since 1.0.0 |
76 | */ |
77 | public int $type = TagType::SINGLE; |
78 | |
79 | /** |
80 | * Get type. |
81 | * |
82 | * @return int |
83 | * |
84 | * @since 1.0.0 |
85 | */ |
86 | public function getType() : int |
87 | { |
88 | return $this->type; |
89 | } |
90 | |
91 | /** |
92 | * Set type. |
93 | * |
94 | * @param int $type Tag type |
95 | * |
96 | * @return void |
97 | * |
98 | * @since 1.0.0 |
99 | */ |
100 | public function setType(int $type = TagType::SINGLE) : void |
101 | { |
102 | $this->type = $type; |
103 | } |
104 | |
105 | /** |
106 | * @return string |
107 | * |
108 | * @since 1.0.0 |
109 | */ |
110 | public function getL11n() : string |
111 | { |
112 | return $this->title instanceof BaseStringL11n ? $this->title->content : $this->title; |
113 | } |
114 | |
115 | /** |
116 | * Set title |
117 | * |
118 | * @param string|BaseStringL11n $title Tag article title |
119 | * @param string $lang Language |
120 | * |
121 | * @return void |
122 | * |
123 | * @since 1.0.0 |
124 | */ |
125 | public function setL11n(string | BaseStringL11n $title, string $lang = ISO639x1Enum::_EN) : void |
126 | { |
127 | if ($title instanceof BaseStringL11n) { |
128 | $this->title = $title; |
129 | } elseif (isset($this->title) && $this->title instanceof BaseStringL11n) { |
130 | $this->title->content = $title; |
131 | } else { |
132 | $this->title = new BaseStringL11n(); |
133 | $this->title->content = $title; |
134 | $this->title->setLanguage($lang); |
135 | } |
136 | } |
137 | |
138 | /** |
139 | * {@inheritdoc} |
140 | */ |
141 | public function toArray() : array |
142 | { |
143 | return [ |
144 | 'id' => $this->id, |
145 | 'title' => $this->title, |
146 | 'color' => $this->color, |
147 | 'type' => $this->type, |
148 | 'owner' => $this->owner, |
149 | ]; |
150 | } |
151 | |
152 | /** |
153 | * {@inheritdoc} |
154 | */ |
155 | public function jsonSerialize() : mixed |
156 | { |
157 | return $this->toArray(); |
158 | } |
159 | } |