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 |
||
| 29 | class AnswerTask extends Task |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * Configure the variables |
||
| 33 | * |
||
| 34 | * @return array |
||
| 35 | */ |
||
| 36 | View Code Duplication | protected function configureVariables() |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Format a question |
||
| 54 | * |
||
| 55 | * @param string $question The question |
||
| 56 | * @param mixed $default Default value |
||
| 57 | * |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | protected function formatQuestion($question, $default = null) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Create a question |
||
| 68 | * |
||
| 69 | * @param string $question The question |
||
| 70 | * @param mixed $default Default value |
||
| 71 | * |
||
| 72 | * @return Question |
||
| 73 | */ |
||
| 74 | protected function createQuestion($question, $default) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Execute the task |
||
| 81 | * |
||
| 82 | * @return mixed |
||
| 83 | */ |
||
| 84 | public function execute() |
||
| 94 | } |
||
| 95 | ?> |
||
| 96 |
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.