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 |
||
| 5 | View Code Duplication | trait ValidationGroupsTrait |
|
|
|
|||
| 6 | { |
||
| 7 | use OptionAccessorsTrait; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @param null|false|array|\Closure $groups |
||
| 11 | * @return $this |
||
| 12 | * @link http://symfony.com/doc/current/reference/forms/types/submit.html#validation-groups |
||
| 13 | */ |
||
| 14 | public function setValidationGroups($groups) |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param null|false|array|\Closure $group |
||
| 21 | * @return $this |
||
| 22 | */ |
||
| 23 | public function addValidationGroup($group) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param string $group |
||
| 35 | * @return bool |
||
| 36 | * @link http://symfony.com/doc/current/reference/forms/types/submit.html#validation-groups |
||
| 37 | */ |
||
| 38 | public function hasValidationGroup($group) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return null|false|array|\Closure |
||
| 45 | * @link http://symfony.com/doc/current/reference/forms/types/submit.html#validation-groups |
||
| 46 | */ |
||
| 47 | public function getValidationGroups() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @return $this |
||
| 54 | */ |
||
| 55 | public function removeValidationGroups() |
||
| 59 | } |
||
| 60 |
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.