Completed
Push — master ( 336c64...8fa798 )
by Łukasz
25:31
created

ExceptionConversion   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 79
c 0
b 0
f 0
rs 10
wmc 11
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A insertBookmark() 0 8 2
A deleteBookmark() 0 8 2
A loadBookmarkDataByUserIdAndLocationId() 0 8 2
A loadUserBookmarks() 0 8 2
A countUserBookmarks() 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\Bookmark\Gateway;
10
11
use Doctrine\DBAL\DBALException;
12
use eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway;
13
use eZ\Publish\SPI\Persistence\Bookmark\Bookmark;
14
use PDOException;
15
use RuntimeException;
16
17
class ExceptionConversion extends Gateway
18
{
19
    /**
20
     * The wrapped gateway.
21
     *
22
     * @var \eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway
23
     */
24
    protected $innerGateway;
25
26
    /**
27
     * ExceptionConversion constructor.
28
     *
29
     * @param \eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway $innerGateway
30
     */
31
    public function __construct(Gateway $innerGateway)
32
    {
33
        $this->innerGateway = $innerGateway;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function insertBookmark(Bookmark $bookmark): int
40
    {
41
        try {
42
            return $this->innerGateway->insertBookmark($bookmark);
43
        } catch (DBALException | PDOException $e) {
44
            throw new RuntimeException('Database error', 0, $e);
45
        }
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function deleteBookmark(int $id): void
52
    {
53
        try {
54
            $this->innerGateway->deleteBookmark($id);
55
        } catch (DBALException | PDOException $e) {
56
            throw new RuntimeException('Database error', 0, $e);
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function loadBookmarkDataByUserIdAndLocationId(int $userId, array $locationId): array
64
    {
65
        try {
66
            return $this->innerGateway->loadBookmarkDataByUserIdAndLocationId($userId, $locationId);
67
        } catch (DBALException | PDOException $e) {
68
            throw new RuntimeException('Database error', 0, $e);
69
        }
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function loadUserBookmarks(int $userId, int $offset = 0, int $limit = -1): array
76
    {
77
        try {
78
            return $this->innerGateway->loadUserBookmarks($userId, $offset, $limit);
79
        } catch (DBALException | PDOException $e) {
80
            throw new RuntimeException('Database error', 0, $e);
81
        }
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function countUserBookmarks(int $userId): int
88
    {
89
        try {
90
            return $this->innerGateway->countUserBookmarks($userId);
91
        } catch (DBALException | PDOException $e) {
92
            throw new RuntimeException('Database error', 0, $e);
93
        }
94
    }
95
}
96