Completed
Push — master ( 7d9afb...4e0ac6 )
by Łukasz
49:46 queued 21:48
created

NotificationService   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 7

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A loadNotifications() 0 4 1
A getNotification() 0 4 1
A markNotificationAsRead() 0 8 1
A getPendingNotificationCount() 0 4 1
A getNotificationCount() 0 4 1
A deleteNotification() 0 8 1
A createNotification() 0 10 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\SignalSlot;
10
11
use eZ\Publish\API\Repository\NotificationService as NotificationServiceInterface;
12
use eZ\Publish\API\Repository\Values\Notification\CreateStruct;
13
use eZ\Publish\API\Repository\Values\Notification\Notification;
14
use eZ\Publish\API\Repository\Values\Notification\NotificationList;
15
use eZ\Publish\Core\SignalSlot\Signal\NotificationService\NotificationDeleteSignal;
16
use eZ\Publish\Core\SignalSlot\Signal\NotificationService\NotificationCreateSignal;
17
use eZ\Publish\Core\SignalSlot\Signal\NotificationService\NotificationReadSignal;
18
19
class NotificationService implements NotificationServiceInterface
20
{
21
    /** @var \eZ\Publish\API\Repository\NotificationService */
22
    protected $service;
23
24
    /** @var \eZ\Publish\Core\SignalSlot\SignalDispatcher */
25
    protected $signalDispatcher;
26
27
    /**
28
     * @param \eZ\Publish\API\Repository\NotificationService $service
29
     * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher
30
     */
31
    public function __construct(NotificationServiceInterface $service, SignalDispatcher $signalDispatcher)
32
    {
33
        $this->service = $service;
34
        $this->signalDispatcher = $signalDispatcher;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function loadNotifications(int $offset, int $limit): NotificationList
41
    {
42
        return $this->service->loadNotifications($offset, $limit);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getNotification(int $notificationId): Notification
49
    {
50
        return $this->service->getNotification($notificationId);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function markNotificationAsRead(Notification $notification): void
57
    {
58
        $this->signalDispatcher->emit(new NotificationReadSignal([
59
            'notificationId' => $notification->id,
60
        ]));
61
62
        $this->service->markNotificationAsRead($notification);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getPendingNotificationCount(): int
69
    {
70
        return $this->service->getPendingNotificationCount();
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getNotificationCount(): int
77
    {
78
        return $this->service->getNotificationCount();
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function deleteNotification(Notification $notification): void
85
    {
86
        $this->signalDispatcher->emit(new NotificationDeleteSignal([
87
            'notificationId' => $notification->id,
88
        ]));
89
90
        $this->service->deleteNotification($notification);
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function createNotification(CreateStruct $createStruct): Notification
97
    {
98
        $this->signalDispatcher->emit(new NotificationCreateSignal([
99
            'ownerId' => $createStruct->ownerId,
100
            'type' => $createStruct->type,
101
            'data' => $createStruct->data,
102
        ]));
103
104
        return $this->service->createNotification($createStruct);
105
    }
106
}
107