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 Lanin\Laravel\SetupWizard\Commands\Steps; |
||
3 | View Code Duplication | class Migrate extends AbstractStep |
|
|
|||
4 | { |
||
5 | /** |
||
6 | * Return command prompt text. |
||
7 | * |
||
8 | * @return string |
||
9 | */ |
||
10 | 3 | public function prompt() |
|
14 | |||
15 | /** |
||
16 | * Prepare step data. |
||
17 | * |
||
18 | * @return mixed |
||
19 | */ |
||
20 | 3 | public function prepare() |
|
24 | |||
25 | /** |
||
26 | * Preview results. |
||
27 | * |
||
28 | * @param mixed $results |
||
29 | * @return void |
||
30 | */ |
||
31 | 3 | public function preview($results) |
|
37 | |||
38 | /** |
||
39 | * Finish step. |
||
40 | * |
||
41 | * @param mixed $results |
||
42 | * @return bool |
||
43 | */ |
||
44 | 3 | public function finish($results) |
|
48 | } |
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.