Completed
Push — ezp-29724 ( 495423...21f3e8 )
by
unknown
46:15 queued 21:42
created

ExceptionConversion   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getUserPreferenceByUserIdAndName() 0 8 2
A countUserPreferences() 0 8 2
A loadUserPreferences() 0 8 2
A setUserPreference() 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\UserPreference\Gateway;
10
11
use Doctrine\DBAL\DBALException;
12
use eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway;
13
use eZ\Publish\SPI\Persistence\UserPreference\UserPreferenceSetStruct;
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\UserPreference\Gateway
23
     */
24
    protected $innerGateway;
25
26
    /**
27
     * ExceptionConversion constructor.
28
     *
29
     * @param \eZ\Publish\Core\Persistence\Legacy\UserPreference\Gateway $innerGateway
30
     */
31
    public function __construct(Gateway $innerGateway)
32
    {
33
        $this->innerGateway = $innerGateway;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getUserPreferenceByUserIdAndName(int $userId, string $name): array
40
    {
41
        try {
42
            return $this->innerGateway->getUserPreferenceByUserIdAndName($userId, $name);
43
        } catch (DBALException | PDOException $e) {
44
            throw new RuntimeException('Database error', 0, $e);
45
        }
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function countUserPreferences(int $userId): int
52
    {
53
        try {
54
            return $this->innerGateway->countUserPreferences($userId);
55
        } catch (DBALException | PDOException $e) {
56
            throw new RuntimeException('Database error', 0, $e);
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function loadUserPreferences(int $userId, int $offset = 0, int $limit = -1): array
64
    {
65
        try {
66
            return $this->innerGateway->loadUserPreferences($userId, $offset, $limit);
67
        } catch (DBALException | PDOException $e) {
68
            throw new RuntimeException('Database error', 0, $e);
69
        }
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function setUserPreference(UserPreferenceSetStruct $setStruct): int
76
    {
77
        try {
78
            return $this->innerGateway->setUserPreference($setStruct);
79
        } catch (DBALException | PDOException $e) {
80
            throw new RuntimeException('Database error', 0, $e);
81
        }
82
    }
83
}
84