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 |
||
26 | abstract class AbstractGenerateCommand extends AbstractCommand |
||
27 | { |
||
28 | /** |
||
29 | * @param InputInterface $input |
||
30 | * @param OutputInterface $output |
||
31 | * @return mixed |
||
32 | */ |
||
33 | abstract public function verify(InputInterface $input, OutputInterface $output) : void; |
||
34 | |||
35 | /** |
||
36 | * Add Force Option |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | 14 | protected function addForceOption() : void |
|
45 | |||
46 | /** |
||
47 | * Add Model Argument |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | 14 | protected function addModelArgument() : void |
|
56 | |||
57 | /** |
||
58 | * Validate Model Argument |
||
59 | * |
||
60 | * @return void |
||
61 | * @throws \Bluzman\Input\InputException |
||
62 | */ |
||
63 | 8 | protected function validateModelArgument() : void |
|
77 | |||
78 | /** |
||
79 | * Add Table Argument |
||
80 | * |
||
81 | * @return void |
||
82 | */ |
||
83 | 14 | protected function addTableArgument() : void |
|
88 | |||
89 | /** |
||
90 | * Validate Table Argument |
||
91 | * |
||
92 | * @return void |
||
93 | * @throws \Bluzman\Input\InputException |
||
94 | */ |
||
95 | 1 | View Code Duplication | protected function validateTableArgument() : void |
109 | |||
110 | /** |
||
111 | * Get Table instance |
||
112 | * |
||
113 | * @param string $model |
||
114 | * |
||
115 | * @return Table |
||
116 | * @throws \Bluzman\Generator\GeneratorException |
||
117 | */ |
||
118 | protected function getTableInstance($model) : Table |
||
133 | |||
134 | /** |
||
135 | * Required for correct mock it |
||
136 | * |
||
137 | * @param string $class |
||
138 | * @return mixed |
||
139 | */ |
||
140 | 1 | protected function getTemplate($class) |
|
145 | |||
146 | /** |
||
147 | * Small wrapper for simplify code |
||
148 | * |
||
149 | * @param string $class |
||
150 | * @param string $file |
||
151 | * @param array $data |
||
152 | * |
||
153 | * @return void |
||
154 | */ |
||
155 | 5 | protected function generateFile($class, $file, array $data = []) : void |
|
169 | |||
170 | /** |
||
171 | * @return string |
||
172 | */ |
||
173 | 2 | protected function getControllerPath($module, $controller) : string |
|
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | */ |
||
184 | 1 | protected function getViewPath($module, $controller) : string |
|
191 | |||
192 | /** |
||
193 | * @todo move it to DB class |
||
194 | * @return array |
||
195 | */ |
||
196 | protected function getPrimaryKey($table) |
||
211 | |||
212 | /** |
||
213 | * @todo move it to DB class |
||
214 | * @return array |
||
215 | */ |
||
216 | protected function getColumns($table) |
||
232 | } |
||
233 |
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.