Passed
Pull Request — master (#1)
by Peter
05:48 queued 02:44
created

ContentList   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 302
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 67
c 1
b 0
f 0
dl 0
loc 302
rs 10
wmc 26

23 Methods

Rating   Name   Duplication   Size   Complexity  
A isWithHtml() 0 3 1
A getName() 0 3 1
A setItems() 0 5 1
A __toString() 0 3 1
A setWithImage() 0 5 1
A getItems() 0 3 1
A getId() 0 3 1
A setTypeId() 0 5 1
A toJSON() 0 25 4
A getDeletedAt() 0 3 1
A isWithImage() 0 3 1
A isProtected() 0 3 1
A setIdentifier() 0 5 1
A setDeletedAt() 0 5 1
A setId() 0 3 1
A __construct() 0 22 1
A setProtected() 0 5 1
A setWithLinks() 0 5 1
A getIdentifier() 0 3 1
A isWithLinks() 0 3 1
A setWithHtml() 0 5 1
A getTypeId() 0 3 1
A setName() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Domain\Entities;
6
7
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
8
use AbterPhp\Framework\Helper\DateHelper;
9
use DateTime;
10
11
class ContentList implements IStringerEntity
12
{
13
    /** @var string */
14
    protected $id;
15
16
    /** @var string */
17
    protected $typeId;
18
19
    /** @var string */
20
    protected $name;
21
22
    /** @var string */
23
    protected $identifier;
24
25
    /** @var bool */
26
    protected $protected;
27
28
    /** @var bool */
29
    protected $withImage;
30
31
    /** @var bool */
32
    protected $withLinks;
33
34
    /** @var bool */
35
    protected $withHtml;
36
37
    /** @var ContentListItem[]|null */
38
    protected $items;
39
40
    /** @var DateTime|null */
41
    protected $deletedAt;
42
43
    /**
44
     * ContentList constructor.
45
     *
46
     * @param string                 $id
47
     * @param string                 $typeId
48
     * @param string                 $name
49
     * @param string                 $identifier
50
     * @param bool                   $protected
51
     * @param bool                   $withImage
52
     * @param bool                   $withLinks
53
     * @param bool                   $withHtml
54
     * @param ContentListItem[]|null $items
55
     * @param DateTime|null          $deletedAt
56
     */
57
    public function __construct(
58
        string $id,
59
        string $typeId,
60
        string $name,
61
        string $identifier,
62
        bool $protected,
63
        bool $withImage,
64
        bool $withLinks,
65
        bool $withHtml,
66
        array $items = null,
67
        ?DateTime $deletedAt = null
68
    ) {
69
        $this->id         = $id;
70
        $this->typeId     = $typeId;
71
        $this->name       = $name;
72
        $this->identifier = $identifier;
73
        $this->protected  = $protected;
74
        $this->withImage  = $withImage;
75
        $this->withLinks  = $withLinks;
76
        $this->withHtml   = $withHtml;
77
        $this->items      = $items;
78
        $this->deletedAt  = $deletedAt;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getId()
85
    {
86
        return $this->id;
87
    }
88
89
    /**
90
     * @param string $id
91
     */
92
    public function setId($id)
93
    {
94
        $this->id = $id;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getTypeId(): string
101
    {
102
        return $this->typeId;
103
    }
104
105
    /**
106
     * @param string $typeId
107
     *
108
     * @return $this
109
     */
110
    public function setTypeId(string $typeId): ContentList
111
    {
112
        $this->typeId = $typeId;
113
114
        return $this;
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getIdentifier(): string
121
    {
122
        return $this->identifier;
123
    }
124
125
    /**
126
     * @param string $identifier
127
     *
128
     * @return $this
129
     */
130
    public function setIdentifier(string $identifier): ContentList
131
    {
132
        $this->identifier = $identifier;
133
134
        return $this;
135
    }
136
137
    /**
138
     * @return string
139
     */
140
    public function getName(): string
141
    {
142
        return $this->name;
143
    }
144
145
    /**
146
     * @param string $name
147
     *
148
     * @return $this
149
     */
150
    public function setName(string $name): ContentList
151
    {
152
        $this->name = $name;
153
154
        return $this;
155
    }
156
157
    /**
158
     * @return bool
159
     */
160
    public function isProtected(): bool
161
    {
162
        return $this->protected;
163
    }
164
165
    /**
166
     * @param bool $protected
167
     *
168
     * @return $this
169
     */
170
    public function setProtected(bool $protected): ContentList
171
    {
172
        $this->protected = $protected;
173
174
        return $this;
175
    }
176
177
    /**
178
     * @return bool
179
     */
180
    public function isWithImage(): bool
181
    {
182
        return $this->withImage;
183
    }
184
185
    /**
186
     * @param bool $withImage
187
     *
188
     * @return $this
189
     */
190
    public function setWithImage(bool $withImage): ContentList
191
    {
192
        $this->withImage = $withImage;
193
194
        return $this;
195
    }
196
197
    /**
198
     * @return bool
199
     */
200
    public function isWithLinks(): bool
201
    {
202
        return $this->withLinks;
203
    }
204
205
    /**
206
     * @param bool $withLinks
207
     *
208
     * @return $this
209
     */
210
    public function setWithLinks(bool $withLinks): ContentList
211
    {
212
        $this->withLinks = $withLinks;
213
214
        return $this;
215
    }
216
217
    /**
218
     * @return bool
219
     */
220
    public function isWithHtml(): bool
221
    {
222
        return $this->withHtml;
223
    }
224
225
    /**
226
     * @param bool $withHtml
227
     *
228
     * @return $this
229
     */
230
    public function setWithHtml(bool $withHtml): ContentList
231
    {
232
        $this->withHtml = $withHtml;
233
234
        return $this;
235
    }
236
237
    /**
238
     * @return ContentListItem[]|null
239
     */
240
    public function getItems(): ?array
241
    {
242
        return $this->items;
243
    }
244
245
    /**
246
     * @param ContentListItem[]|null $items
247
     *
248
     * @return $this
249
     */
250
    public function setItems(?array $items = null): ContentList
251
    {
252
        $this->items = $items;
253
254
        return $this;
255
    }
256
257
    /**
258
     * @return DateTime|null
259
     */
260
    public function getDeletedAt(): ?DateTime
261
    {
262
        return $this->deletedAt;
263
    }
264
265
    /**
266
     * @param DateTime|null $deletedAt
267
     *
268
     * @return $this
269
     */
270
    public function setDeletedAt(?DateTime $deletedAt): ContentList
271
    {
272
        $this->deletedAt = $deletedAt;
273
274
        return $this;
275
    }
276
277
    /**
278
     * @return string
279
     */
280
    public function __toString(): string
281
    {
282
        return $this->getIdentifier();
283
    }
284
285
    /**
286
     * @return string
287
     */
288
    public function toJSON(): string
289
    {
290
        $data = [
291
            'id'         => $this->getId(),
292
            'name'       => $this->getName(),
293
            'identifier' => $this->getIdentifier(),
294
            'protected'  => $this->isProtected(),
295
            'with_image' => $this->isWithImage(),
296
            'with_links' => $this->isWithLinks(),
297
            'with_html'  => $this->isWithHtml(),
298
        ];
299
300
        if ($this->items !== null) {
301
            $items = [];
302
            foreach ($this->items as $item) {
303
                $items[] = json_decode($item->toJSON(), true);
304
            }
305
            $data['items'] = $items;
306
        }
307
308
        if ($this->getDeletedAt()) {
309
            $data['deleted_at'] = DateHelper::formatDateTime($this->getDeletedAt());
310
        }
311
312
        return json_encode($data);
313
    }
314
}
315