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 |
||
| 16 | class AuthController extends Controller |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Show the login page. |
||
| 20 | * |
||
| 21 | * @return \Illuminate\Contracts\View\Factory|Redirect|\Illuminate\View\View |
||
| 22 | */ |
||
| 23 | public function getLogin() |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Handle a login request. |
||
| 34 | * |
||
| 35 | * @param Request $request |
||
| 36 | * |
||
| 37 | * @return mixed |
||
| 38 | */ |
||
| 39 | public function postLogin(Request $request) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * User logout. |
||
| 64 | * |
||
| 65 | * @return Redirect |
||
| 66 | */ |
||
| 67 | public function getLogout(Request $request) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * User setting page. |
||
| 78 | * |
||
| 79 | * @return mixed |
||
| 80 | */ |
||
| 81 | public function getSetting() |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Update user setting. |
||
| 98 | * |
||
| 99 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 100 | */ |
||
| 101 | public function putSetting() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Model-form for user setting. |
||
| 108 | * |
||
| 109 | * @return Form |
||
| 110 | */ |
||
| 111 | protected function settingForm() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @return string|\Symfony\Component\Translation\TranslatorInterface |
||
| 143 | */ |
||
| 144 | protected function getFailedLoginMessage() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Get the post login redirect path. |
||
| 153 | * |
||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | protected function redirectPath() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Send the response after the user was authenticated. |
||
| 167 | * |
||
| 168 | * @param \Illuminate\Http\Request $request |
||
| 169 | * |
||
| 170 | * @return \Illuminate\Http\Response |
||
| 171 | */ |
||
| 172 | protected function sendLoginResponse(Request $request) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Get the login username to be used by the controller. |
||
| 183 | * |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | protected function username() |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Get the guard to be used during authentication. |
||
| 193 | * |
||
| 194 | * @return \Illuminate\Contracts\Auth\StatefulGuard |
||
| 195 | */ |
||
| 196 | protected function guard() |
||
| 200 | } |
||
| 201 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: