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

HtmlDropdownItem   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 72
Duplicated Lines 18.06 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
c 1
b 0
f 0
lcom 1
cbo 5
dl 13
loc 72
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A setDescription() 6 6 1
A setData() 0 3 1
A asOption() 0 5 2
A asMiniAvatar() 7 7 1
A asSearchInput() 0 10 3
A setContent() 0 10 3
A asDivider() 0 4 1
A searchInput() 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\common\html\html5\HtmlInput;
9
use Ajax\service\JArray;
10
11
class HtmlDropdownItem extends HtmlSemDoubleElement {
12
13
	public function __construct($identifier, $content="",$value=NULL,$image=NULL) {
14
		parent::__construct($identifier, "div");
15
		$this->setClass("item");
16
		$this->setContent($content);
17
		if($value!==NULL)
18
			$this->setData($value);
19
		if($image!==NULL)
20
			$this->asMiniAvatar($image);
21
	}
22
23 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...
24
		$descO=new HtmlDoubleElement("desc-".$this->identifier,"span");
25
		$descO->setClass("description");
26
		$descO->setContent($description);
27
		return $this->addContent($descO,true);
28
	}
29
30
	public function setData($value){
31
		$this->setProperty("data-value", $value);
32
	}
33
34
	public function asOption(){
35
		$this->tagName="option";
36
		if($this->getProperty("data-value")!==null)
37
			$this->setProperty("value", $this->getProperty("data-value"));
38
	}
39
40
	/**
41
	 * @param string $image the image src
42
	 * @return \Ajax\common\html\html5\HtmlImg
43
	 */
44 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...
45
		$this->tagName="div";
46
		$img=new HtmlImg("image-".$this->identifier,$image);
47
		$img->setClass("ui mini avatar image");
48
		$this->addContent($img,true);
49
		return $img;
50
	}
51
52
	public function asSearchInput($placeholder=NULL,$icon=NULL){
53
		$this->setClass("ui icon search input");
54
		$input=new HtmlInput("search-".$this->identifier);
55
		if(isset($placeholder))
56
			$input->setProperty("placeholder", $placeholder);
57
		$this->content=$input;
58
		if(isset($icon))
59
			$this->addIcon($icon);
60
		return $this;
61
	}
62
63
	public function setContent($content){
64
		if($content==="-"){
65
			$this->asDivider();
66
		}elseif($content==="-search-"){
67
			$values=\explode(",",$content,-1);
68
			$this->asSearchInput(JArray::getDefaultValue($values, 0, "Search..."),JArray::getDefaultValue($values, 1, "search"));
69
		}else
70
			parent::setContent($content);
71
		return $this;
72
	}
73
74
	public function asDivider(){
75
		$this->content=NULL;
76
		$this->setClass("divider");
77
	}
78
79
	public static function searchInput($placeholder=NULL,$icon=NULL){
80
		return (new HtmlDropdownItem(""))->asSearchInput($placeholder,$icon);
81
	}
82
}