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

HtmlLabel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 11.86 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 3
dl 7
loc 59
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setPointing() 0 3 1
A toCorner() 0 3 1
A asTag() 0 3 1
A setBasic() 0 3 1
A addImage() 0 4 1
A addDetail() 7 7 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\elements;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\common\html\html5\HtmlImg;
7
use Ajax\common\html\HtmlDoubleElement;
8
9
class HtmlLabel extends HtmlSemDoubleElement {
10
11
	public function __construct($identifier,$caption="",$tagName="div") {
12
		parent::__construct($identifier,$tagName);
13
		$this->setProperty("class", "ui label");
14
		$this->content=$caption;
15
	}
16
17
	/**
18
	 * @param string $side
19
	 * @return \Ajax\semantic\html\elements\HtmlLabel
20
	 */
21
	public function setPointing($side=""){
22
		return $this->addToPropertyCtrl("class", $side." pointing",array("right pointing","left pointing"," pointing"));
23
	}
24
25
	/**
26
	 * @param string $side
27
	 * @return \Ajax\semantic\html\elements\HtmlLabel
28
	 */
29
	public function toCorner($side="left"){
30
		return $this->addToPropertyCtrl("class", $side." corner",array("right corner","left corner"));
31
	}
32
33
	/**
34
	 * @return \Ajax\semantic\html\elements\HtmlLabel
35
	 */
36
	public function asTag(){
37
		return $this->addToProperty("class", "tag");
38
	}
39
40
	public function setBasic(){
41
		return $this->addToProperty("class", "basic");
42
	}
43
44
	/**
45
	 * Adds an image to emphasize
46
	 * @param string $src
47
	 * @param string $alt
48
	 * @param string $before
49
	 * @return \Ajax\semantic\html\elements\HtmlLabel
50
	 */
51
	public function addImage($src,$alt="",$before=true){
52
		$this->addToProperty("class", "image");
53
		return $this->addContent(new HtmlImg("image-".$this->identifier,$src,$alt),$before);
0 ignored issues
show
Bug introduced by
It seems like $before defined by parameter $before on line 51 can also be of type string; however, Ajax\common\html\HtmlDoubleElement::addContent() does only seem to accept boolean, 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
	}
55
56
	/**
57
	 * @param string $detail
58
	 * @return \Ajax\common\html\HtmlDoubleElement
59
	 */
60 View Code Duplication
	public function addDetail($detail){
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...
61
		$div=new HtmlDoubleElement("detail-".$this->identifier,$this->tagName);
62
		$div->setClass("detail");
63
		$div->setContent($detail);
64
		$this->addContent($div);
65
		return $div;
66
	}
67
}