Completed
Push — master ( 541276...03d1b2 )
by Jean-Christophe
03:16
created

HtmlMenu::addItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\collections;
4
5
use Ajax\bootstrap\html\HtmlLink;
6
use Ajax\common\html\html5\HtmlCollection;
7
/**
8
 * Semantic Menu component
9
 * @see http://semantic-ui.com/collections/menu.html
10
 * @author jc
11
 * @version 1.001
12
 */
13
class HtmlMenu extends HtmlCollection {
14
15
	public function __construct($identifier, $items=array()) {
16
		parent::__construct($identifier, "div");
17
		$this->setClass("ui menu");
18
		foreach ($items as $item){
19
			$this->addItem($item);
20
		}
21
	}
22
23
	/**
24
	 * Sets the menu type
25
	 * @param string $type one of text,item
26
	 * @return \Ajax\semantic\html\collections\HtmlMenu
27
	 */
28
	public function setType($type=""){
29
		return $this->addToPropertyCtrl("class", $type, array("","item","text"));
30
	}
31
32
	public function setActiveItem($index){
33
		$item=$this->getItem($index);
34
		if($item!==null){
35
			$item->addToProperty("class", "active");
36
		}
37
		return $this;
38
	}
39
40
	/**
41
	 * {@inheritDoc}
42
	 * @see \Ajax\common\html\html5\HtmlCollection::addItem()
43
	 */
44
	public function addItem($item){
45
		$item=parent::addItem($item);
46
		$item->addToProperty("class", "item");
47
	}
48
	/**
49
	 * {@inheritDoc}
50
	 * @see \Ajax\common\html\html5\HtmlCollection::createItem()
51
	 */
52
	protected function createItem($value) {
53
		$itemO=new HtmlLink("item-".\sizeof($this->content),"",$value);
0 ignored issues
show
Bug introduced by
It seems like $value defined by parameter $value on line 52 can also be of type object<Ajax\common\html\HtmlDoubleElement>; however, Ajax\bootstrap\html\HtmlLink::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
54
		return $itemO->setClass("item");
55
	}
56
57
	public function setInverted(){
58
		return $this->addToProperty("class", "inverted");
59
	}
60
}