Completed
Push — master ( b9a8b8...3e8704 )
by Jean-Christophe
03:43
created

HtmlButton   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 76
Duplicated Lines 23.68 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 2
dl 18
loc 76
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 3
A setValue() 0 4 1
A setStyle() 0 3 1
A setFocusable() 0 3 1
A setAnimated() 0 11 1
A addIcon() 7 7 2
A fromArray() 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;
4
5
use Ajax\common\html\HtmlDoubleElement;
6
7
/**
8
 * Semantic Button component
9
 * @see http://semantic-ui.com/elements/button.html
10
 * @author jc
11
 * @version 1.001
12
 */
13
class HtmlButton extends HtmlDoubleElement {
14
15
	/**
16
	 * Constructs an HTML Semantic button
17
	 * @param string $identifier HTML id
18
	 * @param string $value value of the Button
19
	 * @param string $cssStyle btn-default, btn-primary...
20
	 * @param string $onClick JS Code for click event
21
	 */
22 View Code Duplication
	public function __construct($identifier, $value="", $cssStyle=null, $onClick=null) {
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...
23
		parent::__construct($identifier, "button");
24
		$this->setProperty("class", "ui button");
25
		$this->content=$value;
26
		if (isset($cssStyle)) {
27
			$this->setStyle($cssStyle);
28
		}
29
		if (isset($onClick)) {
30
			$this->onClick($onClick);
31
		}
32
	}
33
34
	/**
35
	 * Set the button value
36
	 * @param string $value
37
	 * @return \Ajax\semantic\html\HtmlButton
38
	 */
39
	public function setValue($value) {
40
		$this->content=$value;
41
		return $this;
42
	}
43
44
	/**
45
	 * define the button style
46
	 * @param string|int $cssStyle
47
	 * @return \Ajax\semantic\html\HtmlButton default : ""
48
	 */
49
	public function setStyle($cssStyle) {
50
		return $this->addToProperty("class",$cssStyle);
51
	}
52
53
	public function setFocusable(){
54
		$this->setProperty("tabindex", "0");
55
	}
56
57
	public function setAnimated($content,$animation=""){
58
		$this->setTagName("div");
59
		$this->addToProperty("class", "animated ".$animation);
60
		$visible=new HtmlDoubleElement("visible-".$this->identifier,"div");
61
		$visible->setClass("visible content");
62
		$visible->setContent($this->content);
63
		$hidden=new HtmlDoubleElement("hidden-".$this->identifier,"div");
64
		$hidden->setClass("hidden content");
65
		$hidden->setContent($content);
66
		$this->content=$visible.$hidden;
67
	}
68
69 View Code Duplication
	public function addIcon($icon,$before=true){
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...
70
		$iconO=$icon;
71
		if(\is_string($icon)){
72
			$iconO=new HtmlIcon("icon-".$this->identifier, $icon);
73
		}
74
		$this->addContent($iconO,$before);
75
	}
76
77
	/*
78
	 * (non-PHPdoc)
79
	 * @see \Ajax\common\html\BaseHtml::fromArray()
80
	 */
81
	public function fromArray($array) {
82
		$array=parent::fromArray($array);
83
		foreach ( $array as $key => $value ) {
84
			$this->setProperty($key, $value);
85
		}
86
		return $array;
87
	}
88
}