|
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\Notification; |
|
16
|
|
|
|
|
17
|
|
|
use Kreta\Notifier\Domain\Model\Inbox\UserId; |
|
18
|
|
|
use Kreta\SharedKernel\Domain\Model\AggregateRoot; |
|
19
|
|
|
use Kreta\SharedKernel\Domain\Model\EventSourcedAggregateRoot; |
|
20
|
|
|
use Kreta\SharedKernel\Event\EventStream; |
|
21
|
|
|
|
|
22
|
|
|
class Notification extends AggregateRoot implements EventSourcedAggregateRoot |
|
23
|
|
|
{ |
|
24
|
|
|
private $id; |
|
25
|
|
|
private $body; |
|
26
|
|
|
private $publishedOn; |
|
27
|
|
|
private $readOn; |
|
28
|
|
|
private $status; |
|
29
|
|
|
private $userId; |
|
30
|
|
|
|
|
31
|
|
|
private function __construct(NotificationId $id) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->id = $id; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public static function broadcast(NotificationId $id, UserId $userId, NotificationBody $body) : self |
|
37
|
|
|
{ |
|
38
|
|
|
$notification = new self($id); |
|
39
|
|
|
|
|
40
|
|
|
$notification->publish( |
|
41
|
|
|
new NotificationPublished( |
|
42
|
|
|
$id, |
|
43
|
|
|
$userId, |
|
44
|
|
|
$body, |
|
45
|
|
|
NotificationStatus::unread() |
|
|
|
|
|
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
return $notification; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function markAsRead() : void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->publish( |
|
55
|
|
|
new NotificationMarkedAsRead( |
|
56
|
|
|
$this->id, |
|
57
|
|
|
$this->userId |
|
58
|
|
|
) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function markAsUnread() : void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->publish( |
|
65
|
|
|
new NotificationMarkedAsUnread( |
|
66
|
|
|
$this->id, |
|
67
|
|
|
$this->userId |
|
68
|
|
|
) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
protected function applyNotificationPublished(NotificationPublished $event) : void |
|
73
|
|
|
{ |
|
74
|
|
|
$this->body = $event->body(); |
|
75
|
|
|
$this->userId = $event->userId(); |
|
76
|
|
|
$this->publishedOn = $event->occurredOn(); |
|
77
|
|
|
$this->status = $event->status(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function applyNotificationMarkedAsRead(NotificationMarkedAsRead $event) : void |
|
81
|
|
|
{ |
|
82
|
|
|
$this->readOn = $event->occurredOn(); |
|
83
|
|
|
$this->status = $event->status(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function applyNotificationMarkedAsUnread(NotificationMarkedAsUnread $event) : void |
|
87
|
|
|
{ |
|
88
|
|
|
$this->readOn = null; |
|
89
|
|
|
$this->status = $event->status(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
View Code Duplication |
public static function reconstitute(EventStream $stream) : EventSourcedAggregateRoot |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
$notification = new self($stream->aggregateRootId()); |
|
|
|
|
|
|
95
|
|
|
$events = $stream->events()->toArray(); |
|
96
|
|
|
foreach ($events as $event) { |
|
97
|
|
|
$notification->apply($event); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return $notification; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function id() : NotificationId |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->id; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function __toString() : string |
|
109
|
|
|
{ |
|
110
|
|
|
return (string) $this->id()->id(); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.