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 |
||
13 | class HtmlModal extends HtmlSemDoubleElement { |
||
14 | protected $_params=array(); |
||
15 | protected $_paramParts=array(); |
||
16 | |||
17 | public function __construct($identifier, $header="", $content="", $actions=null) { |
||
29 | |||
30 | public function setHeader($value) { |
||
34 | |||
35 | public function setContent($value) { |
||
39 | |||
40 | public function setActions($actions) { |
||
52 | |||
53 | public function addAction($action){ |
||
68 | |||
69 | /** |
||
70 | * @param int $index |
||
71 | * @return HtmlButton |
||
72 | */ |
||
73 | public function getAction($index){ |
||
76 | |||
77 | public function addContent($content,$before=false){ |
||
81 | |||
82 | View Code Duplication | public function addImageContent($image,$description=NULL){ |
|
95 | |||
96 | View Code Duplication | public function addIconContent($icon,$description=NULL){ |
|
109 | |||
110 | private function addElementInPart($element,$part) { |
||
114 | |||
115 | public function showDimmer($value){ |
||
120 | |||
121 | public function setInverted($recursive=true){ |
||
125 | |||
126 | public function setBasic(){ |
||
129 | |||
130 | |||
131 | public function setTransition($value){ |
||
134 | |||
135 | /** |
||
136 | * render the content of an existing view : $controller/$action and set the response to the modal content |
||
137 | * @param JsUtils $js |
||
138 | * @param Controller $initialController |
||
139 | * @param string $viewName |
||
140 | * @param $params The parameters to pass to the view |
||
141 | */ |
||
142 | public function renderView(JsUtils $js,$initialController,$viewName, $params=array()) { |
||
145 | |||
146 | /** |
||
147 | * render the content of $controller::$action and set the response to the modal content |
||
148 | * @param JsUtils $js |
||
149 | * @param Controller $initialControllerInstance |
||
150 | * @param string $controllerName the controller name |
||
151 | * @param string $actionName the action name |
||
152 | * @param array $params |
||
153 | */ |
||
154 | public function forward(JsUtils $js,$initialControllerInstance,$controllerName,$actionName,$params=NULL){ |
||
157 | |||
158 | /** |
||
159 | * |
||
160 | * {@inheritDoc} |
||
161 | * |
||
162 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
||
163 | */ |
||
164 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
168 | /* |
||
169 | * (non-PHPdoc) |
||
170 | * @see BaseHtml::run() |
||
171 | */ |
||
172 | public function run(JsUtils $js) { |
||
178 | |||
179 | public function jsDo($behavior) { |
||
182 | |||
183 | public function jsHide() { |
||
186 | |||
187 | public function onHidden($js){ |
||
190 | } |
||
191 |
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.