Completed
Push — master ( 586166...fecb59 )
by Paweł
47:58
created

Article::getMetadataByKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.032
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Content Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\ContentBundle\Model;
16
17
use Behat\Transliterator\Transliterator;
18
use Doctrine\Common\Collections\ArrayCollection;
19
use Doctrine\Common\Collections\Collection;
20
use SWP\Component\Common\Model\SoftDeletableTrait;
21
use SWP\Component\Common\Model\TranslatableTrait;
22
23
/**
24
 * Class Article.
25
 */
26
class Article implements ArticleInterface, MediaAwareArticleInterface
27
{
28
    use TranslatableTrait, SoftDeletableTrait;
29
30
    /**
31
     * @var mixed
32
     */
33
    protected $id;
34
35
    /**
36
     * @var string
37
     */
38
    protected $title;
39
40
    /**
41
     * @var string
42
     */
43
    protected $body;
44
45
    /**
46
     * @var string
47
     */
48
    protected $slug;
49
50
    /**
51
     * @var \DateTime
52
     */
53
    protected $publishedAt;
54
55
    /**
56
     * @var string
57
     */
58
    protected $status = ArticleInterface::STATUS_NEW;
59
60
    /**
61
     * @var RouteInterface
62
     */
63
    protected $route;
64
65
    /**
66
     * @var string
67
     */
68
    protected $templateName;
69
70
    /**
71
     * @var \DateTime
72
     */
73
    protected $createdAt;
74
75
    /**
76
     * @var \DateTime
77
     */
78
    protected $updatedAt;
79
80
    /**
81
     * @var \DateTime
82
     */
83
    protected $publishStartDate;
84
85
    /**
86
     * @var \DateTime
87
     */
88
    protected $publishEndDate;
89
90
    /**
91
     * @var bool
92
     */
93
    protected $isPublishable;
94
95
    /**
96
     * @var string
97
     */
98
    protected $metadata;
99
100
    /**
101
     * @var Collection
102
     */
103
    protected $media;
104
105
    /**
106
     * Article constructor.
107
     */
108 40
    public function __construct()
109
    {
110 40
        $this->setCreatedAt(new \DateTime());
111 40
        $this->setPublishable(false);
112 40
        $this->setMedia(new ArrayCollection());
113 40
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function setPublishStartDate(\DateTime $startDate = null)
119
    {
120
        $this->publishStartDate = $startDate;
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126 8
    public function getPublishStartDate()
127
    {
128 8
        return $this->publishStartDate;
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function setPublishEndDate(\DateTime $endDate = null)
135
    {
136
        $this->publishEndDate = $endDate;
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142 8
    public function getPublishEndDate()
143
    {
144 8
        return $this->publishEndDate;
145
    }
146
147
    /**
148
     * {@inheritdoc}
149
     */
150 8
    public function isPublishable()
151
    {
152 8
        return $this->isPublishable;
153
    }
154
155
    /**
156
     * {@inheritdoc}
157
     */
158 40
    public function setPublishable($boolean)
159
    {
160 40
        $this->isPublishable = $boolean;
161 40
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166 3
    public function isPublished()
167
    {
168 3
        return $this->getStatus() === ArticleInterface::STATUS_PUBLISHED;
169
    }
170
171
    /**
172
     * {@inheritdoc}
173
     */
174 16
    public function getCreatedAt()
175
    {
176 16
        return $this->createdAt;
177
    }
178
179
    /**
180
     * {@inheritdoc}
181
     */
182 16
    public function getUpdatedAt()
183
    {
184 16
        return $this->updatedAt;
185
    }
186
187
    /**
188
     * {@inheritdoc}
189
     */
190 40
    public function setCreatedAt(\DateTime $createdAt)
191
    {
192 40
        $this->createdAt = $createdAt;
193 40
    }
194
195
    /**
196
     * {@inheritdoc}
197
     */
198 8
    public function setUpdatedAt(\DateTime $updatedAt)
199
    {
200 8
        $this->updatedAt = $updatedAt;
201 8
    }
202
203
    /**
204
     * {@inheritdoc}
205
     */
206 33
    public function setRoute(RouteInterface $route = null)
207
    {
208 33
        $this->route = $route;
209 33
    }
210
211
    /**
212
     * {@inheritdoc}
213
     */
214 20
    public function getRoute()
215
    {
216 20
        return $this->route;
217
    }
218
219
    /**
220
     * {@inheritdoc}
221
     */
222 20
    public function getId()
223
    {
224 20
        return $this->id;
225
    }
226
227
    /**
228
     * {@inheritdoc}
229
     */
230 18
    public function getBody()
231
    {
232 18
        return $this->body;
233
    }
234
235
    /**
236
     * {@inheritdoc}
237
     */
238 36
    public function setBody($body)
239
    {
240 36
        $this->body = $body;
241 36
    }
242
243
    /**
244
     * {@inheritdoc}
245
     */
246
    public function getMedia()
247
    {
248
        return $this->media;
249
    }
250
251
    /**
252
     * {@inheritdoc}
253
     */
254 40
    public function setMedia(Collection $media)
255
    {
256 40
        $this->media = $media;
257 40
    }
258
259
    /**
260
     * {@inheritdoc}
261
     */
262 17
    public function getTitle()
263
    {
264 17
        return $this->title;
265
    }
266
267
    /**
268
     * {@inheritdoc}
269
     */
270 37
    public function setTitle($title)
271
    {
272 37
        $this->title = $title;
273
274 37
        $this->setSlug(Transliterator::urlize($this->title));
275 37
    }
276
277
    /**
278
     * {@inheritdoc}
279
     */
280 18
    public function getSlug()
281
    {
282 18
        return $this->slug;
283
    }
284
285
    /**
286
     * {@inheritdoc}
287
     */
288 37
    public function setSlug($slug)
289
    {
290 37
        $this->slug = $slug;
291 37
    }
292
293
    /**
294
     * {@inheritdoc}
295
     */
296 16
    public function getPublishedAt()
297
    {
298 16
        return $this->publishedAt;
299
    }
300
301
    /**
302
     * {@inheritdoc}
303
     */
304 31
    public function setPublishedAt(\DateTime $publishedAt)
305
    {
306 31
        $this->publishedAt = $publishedAt;
307 31
    }
308
309
    /**
310
     * {@inheritdoc}
311
     */
312 12
    public function getStatus()
313
    {
314 12
        return $this->status;
315
    }
316
317
    /**
318
     * {@inheritdoc}
319
     */
320 31
    public function setStatus($status)
321
    {
322 31
        $this->status = $status;
323 31
    }
324
325
    /**
326
     * {@inheritdoc}
327
     */
328 12
    public function getTemplateName()
329
    {
330 12
        return $this->templateName;
331
    }
332
333
    /**
334
     * {@inheritdoc}
335
     */
336 10
    public function setTemplateName($templateName)
337
    {
338 10
        $this->templateName = $templateName;
339 10
    }
340
341
    /**
342
     * {@inheritdoc}
343
     */
344 19
    public function getMetadata()
345
    {
346 19
        return json_decode($this->metadata, true);
347
    }
348
349
    /**
350
     * {@inheritdoc}
351
     */
352 3
    public function getMetadataByKey($key)
353
    {
354 3
        $metadata = $this->getMetadata();
355
356 3
        if (isset($metadata[$key])) {
357 3
            return $metadata[$key];
358
        }
359
    }
360
361
    /**
362
     * {@inheritdoc}
363
     */
364 9
    public function setMetadata(array $metadata)
365
    {
366 9
        $this->metadata = json_encode($metadata, true);
367 9
    }
368
369
    /**
370
     * {@inheritdoc}
371
     */
372 3
    public function getSubjectType()
373
    {
374 3
        return 'article';
375
    }
376
377
    /**
378
     * Don't serialize values.
379
     *
380
     * @return array
381
     */
382
    public function __sleep()
383
    {
384
        $this->media = 'Cannot be serializable';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'Cannot be serializable' of type string is incompatible with the declared type object<Doctrine\Common\Collections\Collection> of property $media.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
385
386
        return array_keys(get_object_vars($this));
387
    }
388
}
389