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 |
||
19 | class DataForm extends Widget { |
||
20 | use FormFieldAsTrait,FormTrait; |
||
21 | |||
22 | View Code Duplication | public function __construct($identifier, $modelInstance=NULL) { |
|
28 | |||
29 | View Code Duplication | public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
41 | |||
42 | /** |
||
43 | * @param HtmlForm $form |
||
44 | */ |
||
45 | protected function _generateContent($form){ |
||
58 | |||
59 | /** |
||
60 | * @return HtmlForm |
||
61 | */ |
||
62 | protected function getForm(){ |
||
65 | |||
66 | public function addSeparatorAfter($fieldNum){ |
||
70 | |||
71 | public function getSeparators() { |
||
74 | |||
75 | public function setSeparators($separators) { |
||
79 | |||
80 | public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL){ |
||
85 | |||
86 | public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
||
93 | |||
94 | /** |
||
95 | * {@inheritDoc} |
||
96 | * @see \Ajax\common\Widget::getHtmlComponent() |
||
97 | * @return HtmlForm |
||
98 | */ |
||
99 | public function getHtmlComponent() { |
||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | * @see \Ajax\common\Widget::_setToolbarPosition() |
||
105 | */ |
||
106 | protected function _setToolbarPosition($table, $captions=NULL) { |
||
109 | |||
110 | public function setValidationParams(array $_validationParams) { |
||
114 | } |
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.