Completed
Push — ezp_31107 ( 816f32...9177e0 )
by
unknown
220:54 queued 209:22
created

ExceptionConversion   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 176
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 176
rs 9.6
c 0
b 0
f 0
wmc 35
lcom 1
cbo 1

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createRole() 0 8 2
A loadRole() 0 8 2
A loadRoleByIdentifier() 0 10 2
A loadRoleDraftByRoleId() 0 8 2
A loadRoles() 0 8 2
A loadRolesForContentObjects() 0 10 2
A loadRoleAssignment() 0 8 2
A loadRoleAssignmentsByGroupId() 0 8 2
A loadRoleAssignmentsByRoleId() 0 8 2
A loadPoliciesByUserId() 0 8 2
A updateRole() 0 8 2
A deleteRole() 0 8 2
A publishRoleDraft() 0 8 2
A addPolicy() 0 8 2
A addPolicyLimitations() 0 8 2
A removePolicy() 0 8 2
A removePolicyLimitations() 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\User\Role\Gateway;
10
11
use eZ\Publish\Core\Base\Exceptions\DatabaseException;
12
use eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway;
13
use eZ\Publish\SPI\Persistence\User\Policy;
14
use eZ\Publish\SPI\Persistence\User\RoleUpdateStruct;
15
use eZ\Publish\SPI\Persistence\User\Role;
16
use Doctrine\DBAL\DBALException;
17
use PDOException;
18
19
/**
20
 * @internal Internal exception conversion layer.
21
 */
22
final class ExceptionConversion extends Gateway
23
{
24
    /**
25
     * The wrapped gateway.
26
     *
27
     * @var Gateway
28
     */
29
    private $innerGateway;
30
31
    /**
32
     * Creates a new exception conversion gateway around $innerGateway.
33
     *
34
     * @param Gateway $innerGateway
35
     */
36
    public function __construct(Gateway $innerGateway)
37
    {
38
        $this->innerGateway = $innerGateway;
39
    }
40
41
    public function createRole(Role $role): Role
42
    {
43
        try {
44
            return $this->innerGateway->createRole($role);
45
        } catch (DBALException | PDOException $e) {
46
            throw DatabaseException::wrap($e);
47
        }
48
    }
49
50
    public function loadRole(int $roleId, int $status = Role::STATUS_DEFINED): array
51
    {
52
        try {
53
            return $this->innerGateway->loadRole($roleId, $status);
54
        } catch (DBALException | PDOException $e) {
55
            throw DatabaseException::wrap($e);
56
        }
57
    }
58
59
    public function loadRoleByIdentifier(
60
        string $identifier,
61
        int $status = Role::STATUS_DEFINED
62
    ): array {
63
        try {
64
            return $this->innerGateway->loadRoleByIdentifier($identifier, $status);
65
        } catch (DBALException | PDOException $e) {
66
            throw DatabaseException::wrap($e);
67
        }
68
    }
69
70
    public function loadRoleDraftByRoleId(int $roleId): array
71
    {
72
        try {
73
            return $this->innerGateway->loadRoleDraftByRoleId($roleId);
74
        } catch (DBALException | PDOException $e) {
75
            throw DatabaseException::wrap($e);
76
        }
77
    }
78
79
    public function loadRoles(int $status = Role::STATUS_DEFINED): array
80
    {
81
        try {
82
            return $this->innerGateway->loadRoles();
83
        } catch (DBALException | PDOException $e) {
84
            throw DatabaseException::wrap($e);
85
        }
86
    }
87
88
    public function loadRolesForContentObjects(
89
        array $contentIds,
90
        int $status = Role::STATUS_DEFINED
91
    ): array {
92
        try {
93
            return $this->innerGateway->loadRolesForContentObjects($contentIds);
94
        } catch (DBALException | PDOException $e) {
95
            throw DatabaseException::wrap($e);
96
        }
97
    }
98
99
    public function loadRoleAssignment(int $roleAssignmentId): array
100
    {
101
        try {
102
            return $this->innerGateway->loadRoleAssignment($roleAssignmentId);
103
        } catch (DBALException | PDOException $e) {
104
            throw DatabaseException::wrap($e);
105
        }
106
    }
107
108
    public function loadRoleAssignmentsByGroupId(int $groupId, bool $inherited = false): array
109
    {
110
        try {
111
            return $this->innerGateway->loadRoleAssignmentsByGroupId($groupId, $inherited);
112
        } catch (DBALException | PDOException $e) {
113
            throw DatabaseException::wrap($e);
114
        }
115
    }
116
117
    public function loadRoleAssignmentsByRoleId(int $roleId): array
118
    {
119
        try {
120
            return $this->innerGateway->loadRoleAssignmentsByRoleId($roleId);
121
        } catch (DBALException | PDOException $e) {
122
            throw DatabaseException::wrap($e);
123
        }
124
    }
125
126
    public function loadPoliciesByUserId(int $userId): array
127
    {
128
        try {
129
            return $this->innerGateway->loadPoliciesByUserId($userId);
130
        } catch (DBALException | PDOException $e) {
131
            throw DatabaseException::wrap($e);
132
        }
133
    }
134
135
    public function updateRole(RoleUpdateStruct $role): void
136
    {
137
        try {
138
            $this->innerGateway->updateRole($role);
139
        } catch (DBALException | PDOException $e) {
140
            throw DatabaseException::wrap($e);
141
        }
142
    }
143
144
    public function deleteRole(int $roleId, int $status = Role::STATUS_DEFINED): void
145
    {
146
        try {
147
            $this->innerGateway->deleteRole($roleId, $status);
148
        } catch (DBALException | PDOException $e) {
149
            throw DatabaseException::wrap($e);
150
        }
151
    }
152
153
    public function publishRoleDraft(int $roleDraftId, ?int $originalRoleId = null): void
154
    {
155
        try {
156
            $this->innerGateway->publishRoleDraft($roleDraftId, $originalRoleId);
157
        } catch (DBALException | PDOException $e) {
158
            throw DatabaseException::wrap($e);
159
        }
160
    }
161
162
    public function addPolicy(int $roleId, Policy $policy): Policy
163
    {
164
        try {
165
            return $this->innerGateway->addPolicy($roleId, $policy);
166
        } catch (DBALException | PDOException $e) {
167
            throw DatabaseException::wrap($e);
168
        }
169
    }
170
171
    public function addPolicyLimitations(int $policyId, array $limitations): void
172
    {
173
        try {
174
            $this->innerGateway->addPolicyLimitations($policyId, $limitations);
175
        } catch (DBALException | PDOException $e) {
176
            throw DatabaseException::wrap($e);
177
        }
178
    }
179
180
    public function removePolicy(int $policyId): void
181
    {
182
        try {
183
            $this->innerGateway->removePolicy($policyId);
184
        } catch (DBALException | PDOException $e) {
185
            throw DatabaseException::wrap($e);
186
        }
187
    }
188
189
    public function removePolicyLimitations(int $policyId): void
190
    {
191
        try {
192
            $this->innerGateway->removePolicyLimitations($policyId);
193
        } catch (DBALException | PDOException $e) {
194
            throw DatabaseException::wrap($e);
195
        }
196
    }
197
}
198