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 |
||
| 18 | View Code Duplication | class UserManagementUiHooksSubscriber implements HookSubscriberInterface |
|
|
|
|||
| 19 | { |
||
| 20 | const EDIT_DISPLAY = 'users.ui_hooks.user.display_view'; |
||
| 21 | const EDIT_FORM = 'users.ui_hooks.user.form_edit'; |
||
| 22 | const EDIT_VALIDATE = 'users.ui_hooks.user.validate_edit'; |
||
| 23 | const EDIT_PROCESS = 'users.ui_hooks.user.process_edit'; |
||
| 24 | const DELETE_FORM = 'users.ui_hooks.user.form_delete'; |
||
| 25 | const DELETE_VALIDATE = 'users.ui_hooks.user.validate_delete'; |
||
| 26 | const DELETE_PROCESS = 'users.ui_hooks.user.process_delete'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var TranslatorInterface |
||
| 30 | */ |
||
| 31 | private $translator; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param TranslatorInterface $translator |
||
| 35 | */ |
||
| 36 | public function __construct(TranslatorInterface $translator) |
||
| 40 | |||
| 41 | public function getOwner() |
||
| 45 | |||
| 46 | public function getCategory() |
||
| 50 | |||
| 51 | public function getTitle() |
||
| 55 | |||
| 56 | public function getEvents() |
||
| 68 | } |
||
| 69 |
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.