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 EvaluateTask extends Task |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $expression; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Configure the options |
||
| 38 | * |
||
| 39 | * @return array |
||
| 40 | */ |
||
| 41 | View Code Duplication | protected function configureVariables() |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Set a variable and it's value |
||
| 55 | * |
||
| 56 | * @param string $name The variable name |
||
| 57 | * @param mixed $value The value |
||
| 58 | * |
||
| 59 | * @return $this |
||
| 60 | */ |
||
| 61 | public function offsetSet($name, $value) |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * Execute the task |
||
| 72 | * |
||
| 73 | * @return mixed |
||
| 74 | */ |
||
| 75 | public function execute() |
||
| 82 | } |
||
| 83 | ?> |
||
| 84 |
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.