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 |
||
18 | class AdminController extends FlareController |
||
19 | { |
||
20 | use AuthenticatesUsers { |
||
21 | AuthenticatesUsers::redirectPath insteadof ResetsPasswords; |
||
22 | AuthenticatesUsers::credentials insteadof ResetsPasswords; |
||
23 | AuthenticatesUsers::guard insteadof ResetsPasswords; |
||
24 | } |
||
25 | use ResetsPasswords; |
||
26 | use DispatchesJobs; |
||
27 | |||
28 | /** |
||
29 | * Auth. |
||
30 | * |
||
31 | * @var Guard |
||
32 | */ |
||
33 | protected $auth; |
||
34 | |||
35 | /** |
||
36 | * __construct. |
||
37 | * |
||
38 | * @param Guard $auth |
||
39 | * @param AdminManager $adminManager |
||
40 | */ |
||
41 | public function __construct(Guard $auth, AdminManager $adminManager) |
||
47 | |||
48 | /** |
||
49 | * Show the Dashboard. |
||
50 | * |
||
51 | * @return \Illuminate\Http\Response |
||
52 | */ |
||
53 | View Code Duplication | public function getDashboard() |
|
63 | |||
64 | /** |
||
65 | * Show the login form. |
||
66 | * |
||
67 | * @return \Illuminate\Http\Response |
||
68 | */ |
||
69 | public function getLogin() |
||
73 | |||
74 | /** |
||
75 | * Show the login form. |
||
76 | * |
||
77 | * @return \Illuminate\Http\Response |
||
78 | */ |
||
79 | public function postLogin(Request $request) |
||
83 | |||
84 | /** |
||
85 | * Log the user. |
||
86 | * |
||
87 | * @return \Illuminate\Http\RedirectReponse |
||
88 | */ |
||
89 | public function getLogout() |
||
95 | |||
96 | /** |
||
97 | * Display the form to request a password reset link. |
||
98 | * |
||
99 | * @return \Illuminate\Http\Response |
||
100 | */ |
||
101 | public function getEmail() |
||
105 | |||
106 | /** |
||
107 | * Display the form to request a password reset link. |
||
108 | * |
||
109 | * @return \Illuminate\Http\Response |
||
110 | */ |
||
111 | public function getReset() |
||
115 | |||
116 | /** |
||
117 | * Performs the login redirect action. |
||
118 | * |
||
119 | * If the authenticated user has admin permissions |
||
120 | * then they will be redirected into the admin |
||
121 | * panel. If they do no, they will be sent |
||
122 | * to the homepage of the website. |
||
123 | * |
||
124 | * @return \Illuminate\Http\RedirectReponse |
||
125 | */ |
||
126 | protected function loginRedirect() |
||
135 | |||
136 | /** |
||
137 | * Method is called when the appropriate controller |
||
138 | * method is unable to be found or called. |
||
139 | * |
||
140 | * @param array $parameters |
||
141 | * |
||
142 | * @return \Illuminate\Http\Response |
||
143 | */ |
||
144 | public function missingMethod($parameters = array()) |
||
148 | } |
||
149 |
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: