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 |
||
20 | abstract class MiddlewareAbstract |
||
21 | { |
||
22 | /** |
||
23 | * The Guard implementation. |
||
24 | * |
||
25 | * @var Guard |
||
26 | */ |
||
27 | protected $auth; |
||
28 | |||
29 | /** |
||
30 | * The application implementation. |
||
31 | * |
||
32 | * @var \Illuminate\Contracts\Foundation\Application |
||
33 | */ |
||
34 | protected $app; |
||
35 | |||
36 | /** |
||
37 | * Create a new filter instance. |
||
38 | * |
||
39 | * @param Guard $auth |
||
40 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
41 | */ |
||
42 | public function __construct(Guard $auth, Application $app) |
||
47 | |||
48 | /** |
||
49 | * Return instance of the logged user. |
||
50 | * |
||
51 | * @return User |
||
52 | */ |
||
53 | View Code Duplication | protected function getLoggedUser() |
|
63 | } |
||
64 |
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.