AbstractPublished::serialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace CultuurNet\UDB3\Offer\Events\Moderation;
4
5
use CultuurNet\UDB3\Offer\Events\AbstractEvent;
6
use DateTime;
7
use DateTimeInterface;
8
9
abstract class AbstractPublished extends AbstractEvent
10
{
11
    /**
12
     * @var DateTimeInterface
13
     */
14
    private $publicationDate;
15
16
    final public function __construct(string $itemId, DateTimeInterface $publicationDate)
17
    {
18
        parent::__construct($itemId);
19
20
        $this->publicationDate = $publicationDate;
21
    }
22
23
    public function getPublicationDate(): DateTimeInterface
24
    {
25
        return $this->publicationDate;
26
    }
27
28
    public function serialize(): array
29
    {
30
        return parent::serialize() + [
31
            'publication_date' => $this->publicationDate->format(DateTime::ATOM),
32
        ];
33
    }
34
35
    public static function deserialize(array $data): AbstractPublished
36
    {
37
        return new static(
38
            $data['item_id'],
39
            DateTime::createFromFormat(DateTime::ATOM, $data['publication_date'])
0 ignored issues
show
Security Bug introduced by
It seems like \DateTime::createFromFor...ta['publication_date']) targeting DateTime::createFromFormat() can also be of type false; however, CultuurNet\UDB3\Offer\Ev...ublished::__construct() does only seem to accept object<DateTimeInterface>, did you maybe forget to handle an error condition?
Loading history...
40
        );
41
    }
42
}
43