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 |
||
| 11 | class ResetPasswordController extends Controller |
||
| 12 | { |
||
| 13 | protected $data = []; // the information we send to the view |
||
| 14 | |||
| 15 | /* |
||
| 16 | |-------------------------------------------------------------------------- |
||
| 17 | | Password Reset Controller |
||
| 18 | |-------------------------------------------------------------------------- |
||
| 19 | | |
||
| 20 | | This controller is responsible for handling password reset requests |
||
| 21 | | and uses a simple trait to include this behavior. You're free to |
||
| 22 | | explore this trait and override any methods you wish to tweak. |
||
| 23 | | |
||
| 24 | */ |
||
| 25 | |||
| 26 | use ResetsPasswords; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Create a new controller instance. |
||
| 30 | * |
||
| 31 | * @return void |
||
|
|
|||
| 32 | */ |
||
| 33 | View Code Duplication | public function __construct() |
|
| 34 | { |
||
| 35 | $guard = config('backpack.base.guard', config('auth.defaults.guard')); |
||
| 36 | |||
| 37 | $this->middleware("guest:$guard"); |
||
| 38 | |||
| 39 | // where to redirect after password was reset |
||
| 40 | $this->redirectTo = property_exists($this, 'redirectTo') ? $this->redirectTo : config('backpack.base.route_prefix', 'admin').'/dashboard'; |
||
| 41 | } |
||
| 42 | |||
| 43 | // ------------------------------------------------------- |
||
| 44 | // Laravel overwrites for loading backpack views |
||
| 45 | // ------------------------------------------------------- |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Display the password reset view for the given token. |
||
| 49 | * |
||
| 50 | * If no token is present, display the link request form. |
||
| 51 | * |
||
| 52 | * @param \Illuminate\Http\Request $request |
||
| 53 | * @param string|null $token |
||
| 54 | * |
||
| 55 | * @return \Illuminate\Http\Response |
||
| 56 | */ |
||
| 57 | public function showResetForm(Request $request, $token = null) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Get the broker to be used during password reset. |
||
| 68 | * |
||
| 69 | * @return \Illuminate\Contracts\Auth\PasswordBroker |
||
| 70 | */ |
||
| 71 | public function broker() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Get the guard to be used during password reset. |
||
| 80 | * |
||
| 81 | * @return \Illuminate\Contracts\Auth\StatefulGuard |
||
| 82 | */ |
||
| 83 | protected function guard() |
||
| 89 | } |
||
| 90 |
Adding a
@returnannotation 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.