Completed
Push — master ( 172c54...50fc65 )
by Jean-Christophe
04:31 queued 01:31
created

HtmlDropdownItem   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 132
Duplicated Lines 9.85 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 8
dl 13
loc 132
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 4
A setDescription() 6 6 1
A setData() 0 4 1
A asOption() 0 5 2
A asMiniAvatar() 7 7 1
A asIcon() 0 5 1
A asCircularLabel() 0 7 1
A addMenuItem() 0 9 1
A searchInput() 0 3 1
A divider() 0 3 1
A header() 0 3 1
A circular() 0 3 1
A icon() 0 3 1
A avatar() 0 3 1

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\content;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\common\html\HtmlDoubleElement;
7
use Ajax\common\html\html5\HtmlImg;
8
use Ajax\semantic\html\base\traits\IconTrait;
9
use Ajax\semantic\html\elements\HtmlLabel;
10
use Ajax\semantic\html\elements\HtmlIcon;
11
use Ajax\semantic\html\collections\menus\HtmlMenu;
12
use Ajax\semantic\html\base\traits\MenuItemTrait;
13
14
class HtmlDropdownItem extends HtmlSemDoubleElement {
15
	use IconTrait,MenuItemTrait;
16
	public function __construct($identifier, $content="",$value=NULL,$image=NULL,$description=NULL) {
17
		parent::__construct($identifier, "a");
18
		$this->setClass("item");
19
		$this->setContent($content);
20
		if($value!==NULL)
21
			$this->setData($value);
22
		if($image!==NULL)
23
			$this->asMiniAvatar($image);
24
		if($description!==NULL)
25
			$this->setDescription($description);
26
	}
27
28 View Code Duplication
	public function setDescription($description){
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...
29
		$descO=new HtmlDoubleElement("desc-".$this->identifier,"span");
30
		$descO->setClass("description");
31
		$descO->setContent($description);
32
		return $this->addContent($descO,true);
33
	}
34
35
	public function setData($value){
36
		$this->setProperty("data-value", $value);
37
		return $this;
38
	}
39
40
	public function asOption(){
41
		$this->tagName="option";
42
		if($this->getProperty("data-value")!==null)
43
			$this->setProperty("value", $this->getProperty("data-value"));
44
	}
45
46
	/**
47
	 * @param string $image the image src
48
	 * @return \Ajax\common\html\html5\HtmlImg
49
	 */
50 View Code Duplication
	public function asMiniAvatar($image){
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...
51
		$this->tagName="div";
52
		$img=new HtmlImg("image-".$this->identifier,$image);
53
		$img->setClass("ui mini avatar image");
54
		$this->addContent($img,true);
55
		return $this;
56
	}
57
58
	/**
59
	 * @param string $caption
60
	 * @param string $icon
61
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
62
	 */
63
	public function asIcon($caption,$icon){
64
		$this->setContent($caption);
65
		$this->addContent(new HtmlIcon("", $icon),true);
66
		return $this;
67
	}
68
69
	/**
70
	 * Adds a circular label to the item
71
	 * @param string $color
72
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
73
	 */
74
	public function asCircularLabel($caption,$color){
75
		$this->setContent($caption);
76
		$lbl=new HtmlLabel("");
77
		$lbl->setCircular()->setColor($color)->setEmpty();
78
		$this->addContent($lbl,true);
79
		return $this;
80
	}
81
82
83
84
	public function addMenuItem($items) {
85
		$menu=new HtmlMenu("menu-" . $this->identifier, $items);
86
		$content=$this->content;
87
		$this->setTagName("div");
88
		$this->setProperty("class", "item");
89
		$icon=new HtmlIcon("", "dropdown");
90
		$this->content=[$icon,new HtmlSemDoubleElement("","span","text",$content),$menu];
91
		return $menu;
92
	}
93
94
	/**
95
	 * @param string $placeholder
96
	 * @param string $icon
97
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
98
	 */
99
	public static function searchInput($placeholder=NULL,$icon=NULL){
100
		return (new HtmlDropdownItem(""))->asSearchInput($placeholder,$icon);
101
	}
102
103
	/**
104
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
105
	 */
106
	public static function divider(){
107
		return (new HtmlDropdownItem(""))->asDivider();
108
	}
109
110
	/**
111
	 * @param string $caption
112
	 * @param string $icon
113
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
114
	 */
115
	public static function header($caption=NULL,$icon=NULL){
116
		return (new HtmlDropdownItem(""))->asHeader($caption,$icon);
117
	}
118
119
	/**
120
	 * @param string $caption
121
	 * @param string $color
122
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
123
	 */
124
	public static function circular($caption,$color){
125
		return (new HtmlDropdownItem(""))->asCircularLabel($caption,$color);
126
	}
127
128
	/**
129
	 * @param string $caption
130
	 * @param string $icon
131
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
132
	 */
133
	public static function icon($caption,$icon){
134
		return (new HtmlDropdownItem(""))->asIcon($caption,$icon);
135
	}
136
137
	/**
138
	 * @param unknown $caption
139
	 * @param unknown $image
140
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
141
	 */
142
	public static function avatar($caption,$image){
143
		return (new HtmlDropdownItem("",$caption))->asMiniAvatar($image);
144
	}
145
}