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 namespace Anomaly\UsersModule\Http\Middleware; |
||
| 21 | class CheckSecurity |
||
| 22 | { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The Guard implementation. |
||
| 26 | * |
||
| 27 | * @var Guard |
||
| 28 | */ |
||
| 29 | protected $guard; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * The security utility. |
||
| 33 | * |
||
| 34 | * @var UserSecurity |
||
| 35 | */ |
||
| 36 | protected $security; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The response factory. |
||
| 40 | * |
||
| 41 | * @var ResponseFactory |
||
| 42 | */ |
||
| 43 | protected $response; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The redirector utility. |
||
| 47 | * |
||
| 48 | * @var Redirector |
||
| 49 | */ |
||
| 50 | protected $redirect; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Create a new CheckSecurityRequest instance. |
||
| 54 | * |
||
| 55 | * @param Guard $guard |
||
| 56 | * @param Redirector $redirect |
||
| 57 | * @param ResponseFactory $response |
||
| 58 | * @param UserSecurity $security |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function __construct( |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Handle an incoming request. |
||
| 74 | * |
||
| 75 | * @param \Illuminate\Http\Request $request |
||
| 76 | * @param \Closure $next |
||
| 77 | * @return mixed |
||
| 78 | */ |
||
| 79 | public function handle(Request $request, Closure $next) |
||
| 89 | } |
||
| 90 |
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.