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 EntityCommand extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name of command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $name = 'starter:entity'; |
||
18 | |||
19 | /** |
||
20 | * The description of command. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Create a new entity.'; |
||
25 | |||
26 | /** |
||
27 | * @var Collection |
||
28 | */ |
||
29 | protected $generators = null; |
||
30 | |||
31 | /** |
||
32 | * Execute the command. |
||
33 | * |
||
34 | * @return void |
||
35 | */ |
||
36 | public function fire() |
||
69 | |||
70 | /** |
||
71 | * The array of command arguments. |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | public function getArguments() |
||
86 | |||
87 | /** |
||
88 | * The array of command options. |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | View Code Duplication | public function getOptions() |
|
132 | } |
||
133 |
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.