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 |
||
8 | View Code Duplication | class CustomRuleMakeCommand extends GeneratorCommand |
|
|
|||
9 | { |
||
10 | /** |
||
11 | * The console command signature. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $signature = 'adr:rule {name}'; |
||
16 | |||
17 | /** |
||
18 | * The console command description. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $description = 'Create a new Custom Rule'; |
||
23 | |||
24 | /** |
||
25 | * The type of class being generated. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $type = 'Custom Rule'; |
||
30 | |||
31 | /** |
||
32 | * Get the stub file for the generator. |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | protected function getStub() |
||
40 | |||
41 | /** |
||
42 | * Get the default namespace for the class. |
||
43 | * |
||
44 | * @param string $rootNamespace |
||
45 | * |
||
46 | * @return string |
||
47 | */ |
||
48 | protected function getDefaultNamespace($rootNamespace) |
||
54 | |||
55 | /** |
||
56 | * Get the desired class name from the input. |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | protected function getNameInput() |
||
71 | } |
||
72 |
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.