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 |
||
24 | class HtmlMenu extends HtmlSemCollection { |
||
25 | |||
26 | public function __construct($identifier, $items=array()) { |
||
30 | |||
31 | /** |
||
32 | * Sets the menu type |
||
33 | * @param string $type one of text,item |
||
34 | * @return \Ajax\semantic\html\collections\HtmlMenu |
||
35 | */ |
||
36 | public function setType($type="") { |
||
39 | |||
40 | public function setActiveItem($index) { |
||
47 | |||
48 | private function getItemToInsert($item) { |
||
56 | |||
57 | private function afterInsert($item) { |
||
65 | |||
66 | /** |
||
67 | * |
||
68 | * {@inheritDoc} |
||
69 | * |
||
70 | * @see \Ajax\common\html\html5\HtmlCollection::addItem() |
||
71 | */ |
||
72 | public function addItem($item) { |
||
76 | |||
77 | /** |
||
78 | * |
||
79 | * {@inheritDoc} |
||
80 | * |
||
81 | * @see \Ajax\common\html\HtmlCollection::insertItem() |
||
82 | */ |
||
83 | public function insertItem($item, $position=0) { |
||
87 | |||
88 | public function generateMenuAsItem($menu, $header=null) { |
||
100 | |||
101 | public function addMenuAsItem($menu, $header=null) { |
||
104 | |||
105 | public function addPopupAsItem($value, $identifier, $content="") { |
||
114 | |||
115 | public function addDropdownAsItem($value, $items=NULL) { |
||
122 | |||
123 | /** |
||
124 | * |
||
125 | * {@inheritDoc} |
||
126 | * |
||
127 | * @see \Ajax\common\html\html5\HtmlCollection::createItem() |
||
128 | */ |
||
129 | protected function createItem($value) { |
||
133 | |||
134 | public function setInverted() { |
||
137 | |||
138 | public function setSecondary() { |
||
141 | |||
142 | public function setVertical() { |
||
145 | |||
146 | public function setPosition($value="right") { |
||
149 | |||
150 | public function setPointing($value=Direction::NONE) { |
||
153 | |||
154 | public function asTab($vertical=false) { |
||
162 | |||
163 | public function asPagination() { |
||
169 | |||
170 | public function setFixed() { |
||
173 | |||
174 | public function setFluid() { |
||
177 | |||
178 | public function setCompact() { |
||
181 | |||
182 | /* |
||
183 | * (non-PHPdoc) |
||
184 | * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject() |
||
185 | */ |
||
186 | public function fromDatabaseObject($object, $function) { |
||
193 | |||
194 | /** |
||
195 | * Defines the menu width |
||
196 | * @param int $width |
||
197 | * @return \Ajax\semantic\html\collections\menus\HtmlMenu |
||
198 | */ |
||
199 | View Code Duplication | public function setWidth($width) { |
|
206 | |||
207 | public function addImage($identifier, $src="", $alt="") { |
||
210 | |||
211 | public static function vertical($identifier, $items=array()) { |
||
214 | } |
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.