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 |
||
| 9 | class UsersController extends BaseApiController |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * The name of the model that is used by the base api controller |
||
| 13 | * to preform actions like (add, edit ... etc). |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $model = 'users'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * List of all route actions that the base api controller |
||
| 20 | * will skip permissions check for them. |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | protected $skipPermissionCheck = ['account', 'logout', 'changePassword']; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * List of all route actions that the base api controller |
||
| 27 | * will skip login check for them. |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The validations rules used by the base api controller |
||
| 34 | * to check before add. |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | protected $validationRules = [ |
||
| 38 | 'name' => 'nullable|string', |
||
| 39 | 'email' => 'required|email|unique:users,email,{id}', |
||
| 40 | 'password' => 'nullable|min:6' |
||
| 41 | ]; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The loginProxy implementation. |
||
| 45 | * |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | protected $loginProxy; |
||
| 49 | |||
| 50 | public function __construct(LoginProxy $loginProxy) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Return the logged in user account. |
||
| 58 | * |
||
| 59 | * @return \Illuminate\Http\Response |
||
| 60 | */ |
||
| 61 | public function account() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Block the user. |
||
| 68 | * |
||
| 69 | * @param integer $id Id of the user. |
||
| 70 | * @return \Illuminate\Http\Response |
||
| 71 | */ |
||
| 72 | public function block($id) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Unblock the user. |
||
| 79 | * |
||
| 80 | * @param integer $id Id of the user. |
||
| 81 | * @return \Illuminate\Http\Response |
||
| 82 | */ |
||
| 83 | public function unblock($id) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Logout the user. |
||
| 90 | * |
||
| 91 | * @return \Illuminate\Http\Response |
||
| 92 | */ |
||
| 93 | public function logout() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Handle a registration request. |
||
| 100 | * |
||
| 101 | * @param \Illuminate\Http\Request $request |
||
| 102 | * @return \Illuminate\Http\Response |
||
| 103 | */ |
||
| 104 | View Code Duplication | public function register(Request $request) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Handle a login request to the application. |
||
| 117 | * |
||
| 118 | * @param \Illuminate\Http\Request $request |
||
| 119 | * @return \Illuminate\Http\Response |
||
| 120 | */ |
||
| 121 | public function login(Request $request) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Handle a social login request of the none admin to the application. |
||
| 134 | * |
||
| 135 | * @param \Illuminate\Http\Request $request |
||
| 136 | * @return \Illuminate\Http\Response |
||
| 137 | */ |
||
| 138 | public function loginSocial(Request $request) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Assign the given groups to the given user. |
||
| 151 | * |
||
| 152 | * @param \Illuminate\Http\Request $request |
||
| 153 | * @return \Illuminate\Http\Response |
||
| 154 | */ |
||
| 155 | public function assigngroups(Request $request) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Send a reset link to the given user. |
||
| 167 | * |
||
| 168 | * @param \Illuminate\Http\Request $request |
||
| 169 | * @return \Illuminate\Http\Response |
||
| 170 | */ |
||
| 171 | public function sendreset(Request $request) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Reset the given user's password. |
||
| 180 | * |
||
| 181 | * @param \Illuminate\Http\Request $request |
||
| 182 | * @return \Illuminate\Http\Response |
||
| 183 | */ |
||
| 184 | public function resetpassword(Request $request) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Change the logged in user password. |
||
| 198 | * |
||
| 199 | * @param \Illuminate\Http\Request $request |
||
| 200 | * @return \Illuminate\Http\Response |
||
| 201 | */ |
||
| 202 | View Code Duplication | public function changePassword(Request $request) |
|
| 212 | |||
| 213 | /** |
||
| 214 | * Refresh the expired login token. |
||
| 215 | * |
||
| 216 | * @param string $refreshToken |
||
| 217 | * @return \Illuminate\Http\Response |
||
| 218 | */ |
||
| 219 | public function refreshtoken($refreshToken) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Paginate all users with inthe given group. |
||
| 226 | * |
||
| 227 | * @param \Illuminate\Http\Request $request |
||
| 228 | * @param string $groupName The name of the requested group. |
||
| 229 | * @param integer $perPage Number of rows per page default 15. |
||
| 230 | * @param string $sortBy The name of the column to sort by. |
||
| 231 | * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
||
| 232 | * @return \Illuminate\Http\Response |
||
| 233 | */ |
||
| 234 | public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Save the given data to the logged in user. |
||
| 241 | * |
||
| 242 | * @param \Illuminate\Http\Request $request |
||
| 243 | * @return \Illuminate\Http\Response |
||
| 244 | */ |
||
| 245 | View Code Duplication | public function saveProfile(Request $request) |
|
| 271 | } |
||
| 272 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..