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 |
||
12 | View Code Duplication | class ResetPasswordController extends Controller |
|
|
|||
13 | { |
||
14 | protected $redirectTo = '/'; |
||
15 | |||
16 | use ResetsPasswords; |
||
17 | |||
18 | /** |
||
19 | * Create a new controller instance. |
||
20 | */ |
||
21 | public function __construct() |
||
25 | |||
26 | /** |
||
27 | * Display the password reset view for the given token. |
||
28 | * |
||
29 | * If no token is present, display the link request form. |
||
30 | * |
||
31 | * @param \Illuminate\Http\Request $request |
||
32 | * @param string|null $token |
||
33 | * |
||
34 | * @return \Illuminate\Http\Response |
||
35 | */ |
||
36 | public function showResetForm(Request $request, $token = null) |
||
48 | |||
49 | /** |
||
50 | * Get the response for a successful password reset. |
||
51 | * |
||
52 | * @param string $response |
||
53 | * |
||
54 | * @return \Illuminate\Http\Response |
||
55 | */ |
||
56 | protected function sendResetResponse($response) |
||
62 | |||
63 | protected function guard() |
||
67 | |||
68 | /** |
||
69 | * Get the broker to be used during password reset. |
||
70 | * |
||
71 | * @return \Illuminate\Contracts\Auth\PasswordBroker |
||
72 | */ |
||
73 | public function broker() |
||
77 | } |
||
78 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.