Completed
Push — master ( b2a1ff...4b823c )
by Łukasz
19:14
created

ExceptionConversion::locationSwapped()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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
    /**
97
     * {@inheritdoc}
98
     */
99
    public function locationSwapped(int $location1Id, int $location2Id): void
100
    {
101
        try {
102
            $this->innerGateway->locationSwapped($location1Id, $location2Id);
103
        } catch (DBALException | PDOException $e) {
104
            throw new RuntimeException('Database error', 0, $e);
105
        }
106
    }
107
}
108