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 | class DirectoryCreator extends Creator |
||
9 | { |
||
10 | /** |
||
11 | * Create all directories and files for console. |
||
12 | * |
||
13 | * @param bool $createExample |
||
14 | * @param bool $verbose |
||
15 | */ |
||
16 | public function create($createExample = true, $verbose = true) |
||
33 | |||
34 | /** |
||
35 | * Create the kernel file. |
||
36 | * |
||
37 | * @param bool $createExample |
||
38 | * |
||
39 | * @return bool |
||
40 | */ |
||
41 | View Code Duplication | protected function createKernel($createExample) |
|
58 | |||
59 | /** |
||
60 | * Get the kernel stub. |
||
61 | * |
||
62 | * @param bool $createExample [<description>] |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | protected function getKernelStub($createExample) |
||
82 | |||
83 | /** |
||
84 | * Create an example command. |
||
85 | * |
||
86 | * @return bool |
||
87 | */ |
||
88 | View Code Duplication | protected function createExampleCommand() |
|
105 | |||
106 | /** |
||
107 | * Get the example command stub. |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | protected function getExampleStub() |
||
117 | } |
||
118 |
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.