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 |
||
| 34 | class ValidatorSubject extends AbstractSubject |
||
| 35 | { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The validation errors. |
||
| 39 | * |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | protected $validations = array(); |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Clean up the global data after importing the variants. |
||
| 46 | * |
||
| 47 | * @param string $serial The serial of the actual import |
||
| 48 | * |
||
| 49 | * @return void |
||
| 50 | */ |
||
| 51 | View Code Duplication | public function tearDown($serial) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Return's the array with the validation errors. |
||
| 71 | * |
||
| 72 | * @return array The validation errors |
||
| 73 | */ |
||
| 74 | public function getValidations() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Merge the passed validation errors into the status. |
||
| 81 | * |
||
| 82 | * @param array $validations The validation errors to merge |
||
| 83 | * |
||
| 84 | * @return void |
||
| 85 | */ |
||
| 86 | public function mergeValidations(array $validations) |
||
| 90 | } |
||
| 91 |
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.