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 |
||
10 | class ResetPasswordController extends Controller |
||
11 | { |
||
12 | protected $data = []; // the information we send to the view |
||
13 | |||
14 | /* |
||
15 | |-------------------------------------------------------------------------- |
||
16 | | Password Reset Controller |
||
17 | |-------------------------------------------------------------------------- |
||
18 | | |
||
19 | | This controller is responsible for handling password reset requests |
||
20 | | and uses a simple trait to include this behavior. You're free to |
||
21 | | explore this trait and override any methods you wish to tweak. |
||
22 | | |
||
23 | */ |
||
24 | |||
25 | use ResetsPasswords; |
||
26 | |||
27 | /** |
||
28 | * Create a new controller instance. |
||
29 | * |
||
30 | * @return void |
||
|
|||
31 | */ |
||
32 | View Code Duplication | public function __construct() |
|
41 | |||
42 | // ------------------------------------------------------- |
||
43 | // Laravel overwrites for loading backpack views |
||
44 | // ------------------------------------------------------- |
||
45 | |||
46 | /** |
||
47 | * Display the password reset view for the given token. |
||
48 | * |
||
49 | * If no token is present, display the link request form. |
||
50 | * |
||
51 | * @param \Illuminate\Http\Request $request |
||
52 | * @param string|null $token |
||
53 | * |
||
54 | * @return \Illuminate\Http\Response |
||
55 | */ |
||
56 | public function showResetForm(Request $request, $token = null) |
||
64 | |||
65 | /** |
||
66 | * Get the broker to be used during password reset. |
||
67 | * |
||
68 | * @return \Illuminate\Contracts\Auth\PasswordBroker |
||
69 | */ |
||
70 | public function broker() |
||
76 | |||
77 | /** |
||
78 | * Get the guard to be used during password reset. |
||
79 | * |
||
80 | * @return \Illuminate\Contracts\Auth\StatefulGuard |
||
81 | */ |
||
82 | protected function guard() |
||
86 | } |
||
87 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.