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 |
||
11 | class HtmlShape extends HtmlSemCollection{ |
||
12 | |||
13 | protected $_params=array(); |
||
14 | protected $_autoActive=true; |
||
15 | |||
16 | public function __construct( $identifier, $sides){ |
||
21 | |||
22 | /** |
||
23 | * {@inheritDoc} |
||
24 | * @see \Ajax\common\html\HtmlCollection::createItem() |
||
25 | */ |
||
26 | protected function createItem($value){ |
||
32 | |||
33 | /** |
||
34 | * {@inheritDoc} |
||
35 | * @see \Ajax\common\html\HtmlCollection::createCondition() |
||
36 | */ |
||
37 | protected function createCondition($value){ |
||
40 | |||
41 | /** |
||
42 | * @param int $index |
||
43 | * @return \Ajax\semantic\html\content\HtmlShapeItem |
||
44 | */ |
||
45 | public function getSide($index){ |
||
48 | |||
49 | /** |
||
50 | * @param int $index |
||
51 | * @return mixed|NULL |
||
52 | */ |
||
53 | public function getSideContent($index){ |
||
59 | |||
60 | public function jsDo($action){ |
||
63 | |||
64 | public function jsFlipLeft(){ |
||
67 | |||
68 | public function jsFlipRight(){ |
||
71 | |||
72 | public function jsFlipUp(){ |
||
75 | |||
76 | public function jsFlipDown(){ |
||
79 | |||
80 | public function jsFlipOver(){ |
||
83 | |||
84 | public function jsFlipBack(){ |
||
87 | |||
88 | private function doActionOn($element,$event,$what){ |
||
93 | |||
94 | public function flipLeftOn($element,$event){ |
||
97 | |||
98 | public function flipRightOn($element,$event){ |
||
101 | |||
102 | public function flipUpOn($element,$event){ |
||
105 | |||
106 | public function flipDownOn($element,$event){ |
||
109 | |||
110 | public function flipBackOn($element,$event){ |
||
113 | |||
114 | public function flipOverOn($element,$event){ |
||
117 | |||
118 | public function setActiveSide($index){ |
||
125 | |||
126 | public function asCube(){ |
||
129 | |||
130 | public function asText(){ |
||
133 | |||
134 | public function setWidth($width="initial"){ |
||
140 | |||
141 | public function beforeChange($jsCode){ |
||
144 | |||
145 | /* |
||
146 | * (non-PHPdoc) |
||
147 | * @see BaseHtml::run() |
||
148 | */ |
||
149 | public function run(JsUtils $js) { |
||
155 | |||
156 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
161 | } |
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.