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 AuthController extends BaseDashboardController |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Auth interface. |
||
| 24 | * |
||
| 25 | * @var \Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface |
||
| 26 | */ |
||
| 27 | protected $authRepositoryInterface; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The constructor. |
||
| 31 | * |
||
| 32 | * @param \Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface $authRepositoryInterface |
||
| 33 | */ |
||
| 34 | 21 | public function __construct(AuthRepositoryInterface $authRepositoryInterface) |
|
| 42 | |||
| 43 | /** |
||
| 44 | * Display login screen. |
||
| 45 | * |
||
| 46 | * @return \Illuminate\View\View |
||
| 47 | */ |
||
| 48 | 6 | public function login() |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Authenticate and Validate login input. |
||
| 55 | * |
||
| 56 | * @param Request $request |
||
| 57 | * |
||
| 58 | * @return $this|\Illuminate\Http\RedirectResponse |
||
| 59 | */ |
||
| 60 | 4 | View Code Duplication | public function authentication(Request $request) |
| 78 | |||
| 79 | /** |
||
| 80 | * Display registration screen. |
||
| 81 | * |
||
| 82 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View |
||
| 83 | */ |
||
| 84 | 4 | public function register() |
|
| 94 | |||
| 95 | /** |
||
| 96 | * Register the user. |
||
| 97 | * |
||
| 98 | * @param \Illuminate\Http\Request $request |
||
| 99 | * |
||
| 100 | * @return $this|\Illuminate\Http\RedirectResponse |
||
| 101 | */ |
||
| 102 | 5 | public function registration(Request $request) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * Display activate screen. |
||
| 140 | * |
||
| 141 | * @param \Illuminate\Http\Request $request |
||
| 142 | * |
||
| 143 | * @return $this|\Illuminate\Http\RedirectResponse |
||
| 144 | */ |
||
| 145 | 1 | public function activate(Request $request) |
|
| 163 | |||
| 164 | /** |
||
| 165 | * Activate a user. |
||
| 166 | * |
||
| 167 | * @param \Illuminate\Http\Request $request |
||
| 168 | * |
||
| 169 | * @return $this |
||
| 170 | */ |
||
| 171 | 5 | public function activation(Request $request) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Unauthorized view. |
||
| 203 | * |
||
| 204 | * @return \Illuminate\View\View |
||
| 205 | */ |
||
| 206 | public function unauthorized() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Trigger logout of session. |
||
| 213 | * |
||
| 214 | * @return \Illuminate\Http\RedirectResponse |
||
| 215 | */ |
||
| 216 | 1 | public function logout() |
|
| 222 | } |
||
| 223 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: