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 |
||
7 | class Page extends Entitizer\Utils\Handler { |
||
8 | |||
9 | use Entitizer\Common\Page; |
||
10 | |||
11 | protected $title = 'TITLE_CONTENT_PAGES_EDIT'; |
||
12 | |||
13 | # Handler configuration |
||
14 | |||
15 | protected static $controller = 'Modules\Entitizer\Controller\Page'; |
||
16 | |||
17 | protected static $link = '/admin/content/pages'; |
||
18 | |||
19 | protected static $naming = 'title', $naming_new = ''; |
||
20 | |||
21 | protected static $form_class = 'Modules\Entitizer\Form\Page'; |
||
22 | |||
23 | protected static $message_success_save = 'PAGE_SUCCESS_SAVE'; |
||
24 | |||
25 | protected static $message_error_move = 'PAGE_ERROR_MOVE'; |
||
26 | |||
27 | protected static $message_error_remove = 'PAGE_ERROR_REMOVE'; |
||
28 | |||
29 | protected static $view = 'Blocks/Entitizer/Pages/Main'; |
||
30 | |||
31 | # Add parent additional data |
||
32 | |||
33 | protected function processEntityParent(Template\Block $parent) { |
||
39 | |||
40 | # Add additional parent data for specific entity |
||
41 | |||
42 | protected function processEntity(Template\Block $contents) { |
||
46 | } |
||
47 | } |
||
48 |
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.