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 |
||
9 | class HtmlAccordion extends HtmlSemCollection{ |
||
10 | |||
11 | protected $params=array(); |
||
12 | |||
13 | public function __construct( $identifier, $tagName="div", $baseClass="ui"){ |
||
16 | |||
17 | |||
18 | View Code Duplication | protected function createItem($value){ |
|
27 | |||
28 | protected function createCondition($value){ |
||
31 | |||
32 | public function addPanel($title,$content){ |
||
35 | |||
36 | /** |
||
37 | * render the content of $controller::$action and set the response to a new panel |
||
38 | * @param JsUtils $js |
||
39 | * @param string $title The panel title |
||
40 | * @param Controller $initialController |
||
41 | * @param string $controller a Phalcon controller |
||
42 | * @param string $action a Phalcon action |
||
43 | * @param array $params |
||
44 | */ |
||
45 | public function forwardPanel(JsUtils $js,$title,$initialController,$controller,$action,$params=array()){ |
||
48 | |||
49 | /** |
||
50 | * render the content of an existing view : $controller/$action and set the response to a new panel |
||
51 | * @param JsUtils $js |
||
52 | * @param string $title The panel title |
||
53 | * @param Controller $initialController |
||
54 | * @param string $viewName |
||
55 | * @param $params The parameters to pass to the view |
||
56 | */ |
||
57 | public function renderViewPanel(JsUtils $js,$title,$initialController, $viewName, $params=array()) { |
||
60 | /* |
||
61 | * (non-PHPdoc) |
||
62 | * @see BaseHtml::run() |
||
63 | */ |
||
64 | public function run(JsUtils $js) { |
||
70 | |||
71 | public function setStyled(){ |
||
74 | |||
75 | public function activate($index){ |
||
76 | $this->getItem($index)->setActive(true); |
||
77 | return $this; |
||
78 | } |
||
79 | |||
80 | public function setExclusive($value){ |
||
83 | } |
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.