Passed
Pull Request — master (#1)
by Peter
03:06
created

ContentListItem   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 296
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 64
c 1
b 0
f 0
dl 0
loc 296
rs 10
wmc 24

23 Methods

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