Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
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) |
||
39 | |||
40 | /** |
||
41 | * Create user. |
||
42 | * |
||
43 | * @param user $user |
||
44 | * |
||
45 | * @return mixed |
||
46 | */ |
||
47 | public function createUser(User $user) |
||
57 | |||
58 | /** |
||
59 | * Delete user with the given ID. |
||
60 | * |
||
61 | * @param mixed $userId |
||
62 | */ |
||
63 | public function deleteUser($userId) |
||
73 | |||
74 | /** |
||
75 | * Loads user with user ID. |
||
76 | * |
||
77 | * @param mixed $userId |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | public function load($userId) |
||
91 | |||
92 | /** |
||
93 | * Loads user with user login. |
||
94 | * |
||
95 | * @param string $login |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | public function loadByLogin($login) |
||
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) |
|
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) |
|
145 | |||
146 | /** |
||
147 | * Update the user information specified by the user struct. |
||
148 | * |
||
149 | * @param User $user |
||
150 | */ |
||
151 | public function updateUser(User $user) |
||
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) |
|
177 | |||
178 | /** |
||
179 | * Expires user token with user hash. |
||
180 | * |
||
181 | * @param string $hash |
||
182 | */ |
||
183 | View Code Duplication | public function expireUserToken($hash) |
|
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) |
||
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) |
||
228 | |||
229 | /** |
||
230 | * Remove role from user or user group, by assignment ID. |
||
231 | * |
||
232 | * @param mixed $roleAssignmentId |
||
233 | */ |
||
234 | public function removeRoleAssignmentById($roleAssignmentId) |
||
244 | } |
||
245 |