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

ExceptionConversion   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getNotificationById() 0 8 2
A updateNotification() 0 8 2
A countUserNotifications() 0 8 2
A countUserPendingNotifications() 0 8 2
A loadUserNotifications() 0 8 2
A insert() 0 8 2
A delete() 0 8 2
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\Persistence\Legacy\Notification\Gateway;
10
11
use Doctrine\DBAL\DBALException;
12
use eZ\Publish\Core\Persistence\Legacy\Notification\Gateway;
13
use eZ\Publish\SPI\Persistence\Notification\CreateStruct;
14
use eZ\Publish\SPI\Persistence\Notification\Notification;
15
use PDOException;
16
use RuntimeException;
17
18
class ExceptionConversion extends Gateway
19
{
20
    /**
21
     * The wrapped gateway.
22
     *
23
     * @var \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway
24
     */
25
    protected $innerGateway;
26
27
    /**
28
     * ExceptionConversion constructor.
29
     *
30
     * @param \eZ\Publish\Core\Persistence\Legacy\Notification\Gateway $innerGateway
31
     */
32
    public function __construct(Gateway $innerGateway)
33
    {
34
        $this->innerGateway = $innerGateway;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getNotificationById(int $notificationId): array
41
    {
42
        try {
43
            return $this->innerGateway->getNotificationById($notificationId);
44
        } catch (DBALException | PDOException $e) {
45
            throw new RuntimeException('Database error', 0, $e);
46
        }
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function updateNotification(Notification $notification): void
53
    {
54
        try {
55
            $this->innerGateway->updateNotification($notification);
56
        } catch (DBALException | PDOException $e) {
57
            throw new RuntimeException('Database error', 0, $e);
58
        }
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function countUserNotifications(int $userId): int
65
    {
66
        try {
67
            return $this->innerGateway->countUserNotifications($userId);
68
        } catch (DBALException | PDOException $e) {
69
            throw new RuntimeException('Database error', 0, $e);
70
        }
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function countUserPendingNotifications(int $userId): int
77
    {
78
        try {
79
            return $this->innerGateway->countUserPendingNotifications($userId);
80
        } catch (DBALException | PDOException $e) {
81
            throw new RuntimeException('Database error', 0, $e);
82
        }
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function loadUserNotifications(int $userId, int $offset = 0, int $limit = -1): array
89
    {
90
        try {
91
            return $this->innerGateway->loadUserNotifications($userId, $offset, $limit);
92
        } catch (DBALException | PDOException $e) {
93
            throw new RuntimeException('Database error', 0, $e);
94
        }
95
    }
96
97
    /**
98
     * Store Notification ValueObject in persistent storage.
99
     *
100
     * @param \eZ\Publish\SPI\Persistence\Notification\CreateStruct $notification
101
     *
102
     * @return int
103
     */
104
    public function insert(CreateStruct $notification): int
105
    {
106
        try {
107
            return $this->innerGateway->insert($notification);
108
        } catch (DBALException | PDOException $e) {
109
            throw new RuntimeException('Database error', 0, $e);
110
        }
111
    }
112
113
    /**
114
     * @param int $notificationId
115
     */
116
    public function delete(int $notificationId): void
117
    {
118
        try {
119
            $this->innerGateway->delete($notificationId);
120
        } catch (DBALException | PDOException $e) {
121
            throw new RuntimeException('Database error', 0, $e);
122
        }
123
    }
124
}
125