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

Notification   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 63
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A broadcast() 0 4 1
A read() 0 5 1
A unread() 0 5 1
A id() 0 4 1
A body() 0 4 1
A publishedOn() 0 4 1
A readOn() 0 4 1
A status() 0 4 1
A __toString() 0 4 1
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