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 |
||
20 | class ProjectUserRoleModel extends Model |
||
21 | { |
||
22 | /** |
||
23 | * SQL table name. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | const TABLE = 'project_has_users'; |
||
28 | |||
29 | /** |
||
30 | * Get the list of active project for the given user. |
||
31 | * |
||
32 | * @param int $user_id |
||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | public function getActiveProjectsByUser($user_id) |
||
40 | |||
41 | /** |
||
42 | * Get the list of project visible for the given user. |
||
43 | * |
||
44 | * @param int $user_id |
||
45 | * @param array $status |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | public function getProjectsByUser($user_id, $status = [ProjectModel::ACTIVE, ProjectModel::INACTIVE]) |
||
68 | |||
69 | /** |
||
70 | * For a given project get the role of the specified user. |
||
71 | * |
||
72 | * @param int $project_id |
||
73 | * @param int $user_id |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getUserRole($project_id, $user_id) |
||
96 | |||
97 | /** |
||
98 | * Get all users associated directly to the project. |
||
99 | * |
||
100 | * @param int $project_id |
||
101 | * |
||
102 | * @return array |
||
103 | */ |
||
104 | View Code Duplication | public function getUsers($project_id) |
|
114 | |||
115 | /** |
||
116 | * Get all users (fetch users from groups). |
||
117 | * |
||
118 | * @param int $project_id |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | public function getAllUsers($project_id) |
||
130 | |||
131 | /** |
||
132 | * Get users grouped by role. |
||
133 | * |
||
134 | * @param int $project_id Project id |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | public function getAllUsersGroupedByRole($project_id) |
||
156 | |||
157 | /** |
||
158 | * Get list of users that can be assigned to a task (only Manager and Member). |
||
159 | * |
||
160 | * @param int $project_id |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | public function getAssignableUsers($project_id) |
||
183 | |||
184 | /** |
||
185 | * Get list of users that can be assigned to a task (only Manager and Member). |
||
186 | * |
||
187 | * @param int $project_id Project id |
||
188 | * @param bool $unassigned Prepend the 'Unassigned' value |
||
189 | * @param bool $everybody Prepend the 'Everbody' value |
||
190 | * @param bool $singleUser If there is only one user return only this user |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | public function getAssignableUsersList($project_id, $unassigned = true, $everybody = false, $singleUser = false) |
||
212 | |||
213 | /** |
||
214 | * Add a user to the project. |
||
215 | * |
||
216 | * @param int $project_id |
||
217 | * @param int $user_id |
||
218 | * @param string $role |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | View Code Duplication | public function addUser($project_id, $user_id, $role) |
|
230 | |||
231 | |||
232 | View Code Duplication | public function getRemoveUser() |
|
248 | |||
249 | |||
250 | /** |
||
251 | * Remove a user from the project. |
||
252 | * |
||
253 | * @param int $project_id |
||
254 | * @param int $user_id |
||
255 | * |
||
256 | * @return bool |
||
257 | */ |
||
258 | public function removeUser($project_id, $user_id) |
||
262 | |||
263 | /** |
||
264 | * Change a user role for the project. |
||
265 | * |
||
266 | * @param int $project_id |
||
267 | * @param int $user_id |
||
268 | * @param string $role |
||
269 | * |
||
270 | * @return bool |
||
271 | */ |
||
272 | public function changeUserRole($project_id, $user_id, $role) |
||
281 | |||
282 | /** |
||
283 | * Copy user access from a project to another one. |
||
284 | * |
||
285 | * @param int $project_src_id |
||
286 | * @param int $project_dst_id |
||
287 | * |
||
288 | * @return bool |
||
289 | */ |
||
290 | View Code Duplication | public function duplicate($project_src_id, $project_dst_id) |
|
308 | } |
||
309 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.