Completed
Push — master ( 59965c...4339a8 )
by
unknown
114:08 queued 95:41
created

ExceptionConversion::loadUserByToken()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the User Gateway class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Legacy\User\Gateway;
10
11
use eZ\Publish\Core\Persistence\Legacy\User\Gateway;
12
use eZ\Publish\SPI\Persistence\User;
13
use Doctrine\DBAL\DBALException;
14
use eZ\Publish\SPI\Persistence\User\UserTokenUpdateStruct;
15
use PDOException;
16
use RuntimeException;
17
18
/**
19
 * Base class for user gateways.
20
 */
21
class ExceptionConversion extends Gateway
22
{
23
    /**
24
     * The wrapped gateway.
25
     *
26
     * @var Gateway
27
     */
28
    protected $innerGateway;
29
30
    /**
31
     * Creates a new exception conversion gateway around $innerGateway.
32
     *
33
     * @param Gateway $innerGateway
34
     */
35
    public function __construct(Gateway $innerGateway)
36
    {
37
        $this->innerGateway = $innerGateway;
38
    }
39
40
    /**
41
     * Create user.
42
     *
43
     * @param user $user
44
     *
45
     * @return mixed
46
     */
47
    public function createUser(User $user)
48
    {
49
        try {
50
            return $this->innerGateway->createUser($user);
51
        } catch (DBALException $e) {
52
            throw new RuntimeException('Database error', 0, $e);
53
        } catch (PDOException $e) {
54
            throw new RuntimeException('Database error', 0, $e);
55
        }
56
    }
57
58
    /**
59
     * Delete user with the given ID.
60
     *
61
     * @param mixed $userId
62
     */
63
    public function deleteUser($userId)
64
    {
65
        try {
66
            return $this->innerGateway->deleteUser($userId);
67
        } catch (DBALException $e) {
68
            throw new RuntimeException('Database error', 0, $e);
69
        } catch (PDOException $e) {
70
            throw new RuntimeException('Database error', 0, $e);
71
        }
72
    }
73
74
    /**
75
     * Loads user with user ID.
76
     *
77
     * @param mixed $userId
78
     *
79
     * @return array
80
     */
81
    public function load($userId)
82
    {
83
        try {
84
            return $this->innerGateway->load($userId);
85
        } catch (DBALException $e) {
86
            throw new RuntimeException('Database error', 0, $e);
87
        } catch (PDOException $e) {
88
            throw new RuntimeException('Database error', 0, $e);
89
        }
90
    }
91
92
    /**
93
     * Loads user with user login.
94
     *
95
     * @param string $login
96
     *
97
     * @return array
98
     */
99
    public function loadByLogin($login)
100
    {
101
        try {
102
            return $this->innerGateway->loadByLogin($login);
103
        } catch (DBALException $e) {
104
            throw new RuntimeException('Database error', 0, $e);
105
        } catch (PDOException $e) {
106
            throw new RuntimeException('Database error', 0, $e);
107
        }
108
    }
109
110
    /**
111
     * Loads user with user email.
112
     *
113
     * @param string $email
114
     *
115
     * @return array
116
     */
117 View Code Duplication
    public function loadByEmail($email)
118
    {
119
        try {
120
            return $this->innerGateway->loadByEmail($email);
121
        } catch (\DBALException $e) {
0 ignored issues
show
Bug introduced by
The class DBALException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
122
            throw new \RuntimeException('Database error', 0, $e);
123
        } catch (\PDOException $e) {
124
            throw new \RuntimeException('Database error', 0, $e);
125
        }
126
    }
127
128
    /**
129
     * Loads a user with user hash key.
130
     *
131
     * @param string $hash
132
     *
133
     * @return array
134
     */
135 View Code Duplication
    public function loadUserByToken($hash)
136
    {
137
        try {
138
            return $this->innerGateway->loadUserByToken($hash);
139
        } catch (DBALException $e) {
140
            throw new \RuntimeException('Database error', 0, $e);
141
        } catch (\PDOException $e) {
142
            throw new \RuntimeException('Database error', 0, $e);
143
        }
144
    }
145
146
    /**
147
     * Update the user information specified by the user struct.
148
     *
149
     * @param User $user
150
     */
151
    public function updateUser(User $user)
152
    {
153
        try {
154
            return $this->innerGateway->updateUser($user);
155
        } catch (DBALException $e) {
156
            throw new RuntimeException('Database error', 0, $e);
157
        } catch (PDOException $e) {
158
            throw new RuntimeException('Database error', 0, $e);
159
        }
160
    }
161
162
    /**
163
     * Update the user token information specified by the user token struct.
164
     *
165
     * @param UserTokenUpdateStruct $userTokenUpdateStruct
166
     */
167 View Code Duplication
    public function updateUserToken(UserTokenUpdateStruct $userTokenUpdateStruct)
168
    {
169
        try {
170
            return $this->innerGateway->updateUserToken($userTokenUpdateStruct);
171
        } catch (DBALException $e) {
172
            throw new RuntimeException('Database error', 0, $e);
173
        } catch (PDOException $e) {
174
            throw new RuntimeException('Database error', 0, $e);
175
        }
176
    }
177
178
    /**
179
     * Expires user token with user hash.
180
     *
181
     * @param string $hash
182
     */
183 View Code Duplication
    public function expireUserToken($hash)
184
    {
185
        try {
186
            return $this->innerGateway->expireUserToken($hash);
187
        } catch (DBALException $e) {
188
            throw new RuntimeException('Database error', 0, $e);
189
        } catch (PDOException $e) {
190
            throw new RuntimeException('Database error', 0, $e);
191
        }
192
    }
193
194
    /**
195
     * Assigns role to user with given limitation.
196
     *
197
     * @param mixed $contentId
198
     * @param mixed $roleId
199
     * @param array $limitation
200
     */
201
    public function assignRole($contentId, $roleId, array $limitation)
202
    {
203
        try {
204
            return $this->innerGateway->assignRole($contentId, $roleId, $limitation);
205
        } catch (DBALException $e) {
206
            throw new RuntimeException('Database error', 0, $e);
207
        } catch (PDOException $e) {
208
            throw new RuntimeException('Database error', 0, $e);
209
        }
210
    }
211
212
    /**
213
     * Remove role from user or user group.
214
     *
215
     * @param mixed $contentId
216
     * @param mixed $roleId
217
     */
218
    public function removeRole($contentId, $roleId)
219
    {
220
        try {
221
            return $this->innerGateway->removeRole($contentId, $roleId);
222
        } catch (DBALException $e) {
223
            throw new RuntimeException('Database error', 0, $e);
224
        } catch (PDOException $e) {
225
            throw new RuntimeException('Database error', 0, $e);
226
        }
227
    }
228
229
    /**
230
     * Remove role from user or user group, by assignment ID.
231
     *
232
     * @param mixed $roleAssignmentId
233
     */
234
    public function removeRoleAssignmentById($roleAssignmentId)
235
    {
236
        try {
237
            return $this->innerGateway->removeRoleAssignmentById($roleAssignmentId);
238
        } catch (DBALException $e) {
239
            throw new RuntimeException('Database error', 0, $e);
240
        } catch (PDOException $e) {
241
            throw new RuntimeException('Database error', 0, $e);
242
        }
243
    }
244
}
245