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

Notification::id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Model\Inbox;
16
17
class Notification
18
{
19
    private $id;
20
    private $body;
21
    private $publishedOn;
22
    private $readOn;
23
    private $status;
24
25
    private function __construct(NotificationId $id, NotificationBody $body)
26
    {
27
        $this->id = $id;
28
        $this->body = $body;
29
        $this->publishedOn = new \DateTimeImmutable();
30
        $this->status = NotificationStatus::unread();
31
    }
32
33
    public static function broadcast(NotificationId $id, NotificationBody $body) : self
34
    {
35
        return new self($id, $body);
36
    }
37
38
    public function read() : void
39
    {
40
        $this->status = NotificationStatus::read();
41
        $this->readOn = new \DateTimeImmutable();
42
    }
43
44
    public function unread() : void
45
    {
46
        $this->status = NotificationStatus::unread();
47
        $this->readOn = null;
48
    }
49
50
    public function id() : NotificationId
51
    {
52
        return $this->id;
53
    }
54
55
    public function body() : NotificationBody
56
    {
57
        return $this->body;
58
    }
59
60
    public function publishedOn() : \DateTimeInterface
61
    {
62
        return $this->publishedOn;
63
    }
64
65
    public function readOn() : ?\DateTimeInterface
66
    {
67
        return $this->readOn;
68
    }
69
70
    public function status() : NotificationStatus
71
    {
72
        return $this->status;
73
    }
74
75
    public function __toString() : string
76
    {
77
        return (string) $this->id()->id();
78
    }
79
}
80