Completed
Pull Request — master (#366)
by Beñat
04:53
created

Notification::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 6
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\Notifier\Domain\ReadModel\Inbox\Notification;
16
17
class Notification implements \JsonSerializable
18
{
19
    public $id;
20
    public $userId;
21
    public $body;
22
    public $publishedOn;
23
    public $readOn;
24
    public $status;
25
26
    public function __construct(
27
        string $id,
28
        string $userId,
29
        string $body,
30
        int $publishedOn,
31
        string $status,
32
        int $readOn = null
33
    ) {
34
        $this->id = $id;
35
        $this->userId = $userId;
36
        $this->body = $body;
37
        $this->publishedOn = $publishedOn;
38
        $this->status = $status;
39
        $this->readOn = $readOn;
40
    }
41
42
    public static function fromArray(array $notificationData) : self
43
    {
44
        return new self(
45
            $notificationData['id'],
46
            $notificationData['user_id'],
47
            $notificationData['body'],
48
            $notificationData['published_on'],
49
            $notificationData['status'],
50
            $notificationData['read_on']
51
        );
52
    }
53
54
    public function jsonSerialize() : array
55
    {
56
        return [
57
            'id'           => $this->id,
58
            'user_id'      => $this->userId,
59
            'body'         => $this->body,
60
            'published_on' => $this->publishedOn,
61
            'status'       => $this->status,
62
            'read_on'      => $this->readOn,
63
        ];
64
    }
65
}
66