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 |
||
7 | class DirectoryCreator extends Creator |
||
8 | { |
||
9 | /** |
||
10 | * Create all directories and files for console. |
||
11 | */ |
||
12 | public function create() |
||
18 | |||
19 | /** |
||
20 | * Create cosnole directory structure. |
||
21 | */ |
||
22 | protected function createAllDirectories() |
||
35 | |||
36 | /** |
||
37 | * Create the kernel file. |
||
38 | */ |
||
39 | protected function createKernel() |
||
48 | |||
49 | /** |
||
50 | * Get the kernel stub. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | protected function getKernelStub() |
||
60 | |||
61 | /** |
||
62 | * Resolve the console namespace. |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | View Code Duplication | protected function resolveConsoleNamespace() |
|
74 | } |
||
75 |
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.