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 | final class PreCommitProcessor extends Processor |
||
11 | { |
||
12 | private $simpleTools = ['composer', 'jsonlint', 'phplint', 'phpmd']; |
||
13 | const HOOK_NAME = 'pre-commit'; |
||
14 | |||
15 | /** |
||
16 | * @param array $configData |
||
17 | * |
||
18 | * @return array |
||
19 | */ |
||
20 | 10 | public function execute(array $configData) |
|
33 | |||
34 | /** |
||
35 | * @param array $configData |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | 10 | View Code Duplication | private function enableHook(array $configData) |
58 | |||
59 | /** |
||
60 | * @param array $execute |
||
61 | */ |
||
62 | 9 | private function configSimpleTools(array $execute) |
|
71 | |||
72 | /** |
||
73 | * @param array $execute |
||
74 | */ |
||
75 | 9 | private function configComplexTools(array $execute) |
|
81 | |||
82 | /** |
||
83 | * @param array $execute |
||
84 | */ |
||
85 | 9 | private function configPhpCs(array $execute) |
|
91 | |||
92 | /** |
||
93 | * @param array $execute |
||
94 | */ |
||
95 | 9 | private function configPhpCsFixer(array $execute) |
|
101 | |||
102 | 7 | private function configPhpUnit(array $execute) |
|
108 | |||
109 | /** |
||
110 | * @param string $tool |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 8 | private function setQuestionTool($tool) |
|
118 | |||
119 | /** |
||
120 | * @param array $hookData |
||
121 | */ |
||
122 | 9 | private function configMessage(array $hookData) |
|
127 | } |
||
128 |
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.