Completed
Push — master ( 409900...f20dfb )
by Jean-Christophe
03:24
created

HtmlMenu   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 16 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 3
dl 8
loc 50
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A setType() 0 3 1
A addItem() 0 8 2
A getItem() 8 8 2
A setActiveItem() 0 7 2

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace Ajax\semantic\html\collections;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\bootstrap\html\HtmlLink;
7
use Ajax\common\html\HtmlDoubleElement;
8
9
class HtmlMenu extends HtmlSemDoubleElement {
10
11
	public function __construct($identifier, $items=array()) {
12
		parent::__construct($identifier, "div");
13
		$this->setClass("ui menu");
14
		foreach ($items as $item){
15
			$this->addItem($item);
16
		}
17
	}
18
19
	/**
20
	 * Sets the menu type
21
	 * @param string $type one of text,item
22
	 * @return \Ajax\semantic\html\collections\HtmlMenu
23
	 */
24
	public function setType($type=""){
25
		return $this->addToPropertyCtrl("class", $type, array("","item","text"));
26
	}
27
28
	public function addItem($item){
29
		$itemO=$item;
30
		if(\is_string($item)){
31
				$itemO=new HtmlLink("item-".\sizeof($this->content),"",$item);
32
				$itemO->setClass("item");
33
		}
34
		$this->addContent($itemO);
35
	}
36
37
	/**
38
	 * Return the item at index
39
	 * @param int $index
40
	 * @return HtmlDoubleElement
41
	 */
42 View Code Duplication
	public function getItem($index) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
43
		if (is_int($index))
44
			return $this->content[$index];
45
			else {
46
				$elm=$this->getElementById($index, $this->content);
47
				return $elm;
48
			}
49
	}
50
51
	public function setActiveItem($index){
52
		$item=$this->getItem($index);
53
		if($item!==null){
54
			$item->addToProperty("class", "active");
55
		}
56
		return $this;
57
	}
58
}