Completed
Push — master ( e9bdcb...b0560a )
by Jean-Christophe
04:52
created

HtmlProgress   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 92
Duplicated Lines 2.17 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
c 1
b 0
f 0
lcom 1
cbo 4
dl 2
loc 92
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A setLabel() 0 4 1
A createBar() 0 5 1
A setIndicating() 0 3 1
A setActive() 0 3 1
A compile() 0 4 1
A jsSetValue() 0 3 1
A jsIncValue() 0 3 1
A jsDecValue() 0 3 1
A setTextValues() 0 12 2
A onChange() 0 3 1
A run() 2 6 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\modules;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\JsUtils;
7
use Ajax\service\JArray;
8
use Phalcon\Mvc\View;
9
10
class HtmlProgress extends HtmlSemDoubleElement {
11
	private $_params=array ();
12
13
	public function __construct($identifier, $value=NULL, $label=NULL) {
14
		parent::__construct($identifier, "div", "ui progress");
15
		if (isset($value) === true)
16
			$this->setProperty("data-percent", $value);
17
		$this->createBar();
18
		if (isset($label) === true)
19
			$this->setLabel($label);
20
	}
21
22
	public function setLabel($label) {
23
		$this->content["label"]=new HtmlSemDoubleElement("lbl-" . $this->identifier, "div", "label", $label);
24
		return $this;
25
	}
26
27
	private function createBar() {
28
		$bar=new HtmlSemDoubleElement("bar-" . $this->identifier, "div", "bar", new HtmlSemDoubleElement("progress-" . $this->identifier, "div", "progress"));
29
		$this->content["bar"]=$bar;
30
		return $this;
31
	}
32
33
	public function setIndicating() {
34
		return $this->addToProperty("class", "indicating");
35
	}
36
37
	public function setActive() {
38
		return $this->addToProperty("class", "active");
39
	}
40
41
	/**
42
	 *
43
	 * {@inheritDoc}
44
	 *
45
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
46
	 */
47
	public function compile(JsUtils $js=NULL, View $view=NULL) {
48
		$this->content=JArray::sortAssociative($this->content, [ "bar","label" ]);
49
		return parent::compile($js, $view);
50
	}
51
52
	public function jsSetValue($value) {
53
		return '$("#' . $this->identifier . '").progress({value:' . $value . '});';
54
	}
55
56
	public function jsIncValue() {
57
		return '$("#' . $this->identifier . '").progress("increment");';
58
	}
59
60
	public function jsDecValue() {
61
		return '$("#' . $this->identifier . '").progress("decrement");';
62
	}
63
64
	/**
65
	 *
66
	 * @param mixed $active
67
	 * @param mixed $error
68
	 * @param mixed $success
69
	 * @param mixed $warning
70
	 * @param mixed $percent
71
	 * @param mixed $ratio
72
	 * @return HtmlProgress
73
	 */
74
	public function setTextValues($active=false, $error=false, $success=false, $warning=false, $percent="{percent}%", $ratio="{value} of {total}") {
75
		if (\is_array($active) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
76
			$array=$active;
77
			$active=JArray::getDefaultValue($array, "active", false);
78
			$success=JArray::getDefaultValue($array, "success", $success);
79
			$warning=JArray::getDefaultValue($array, "warning", $warning);
80
			$percent=JArray::getDefaultValue($array, "percent", $percent);
81
			$ratio=JArray::getDefaultValue($array, "ratio", $ratio);
82
		}
83
		$this->_params["text"]="%{active  : " . \var_export($active, true) . ",error: " . \var_export($error, true) . ",success : " . \var_export($success, true) . ",warning : " . \var_export($warning, true) . ",percent : " . \var_export($percent, true) . ",ratio   : " . \var_export($ratio, true) . "}%";
84
		return $this;
85
	}
86
87
	public function onChange($jsCode) {
88
		return $this->_params["onChange"]="%function(percent, value, total){" . $jsCode . "}%";
89
	}
90
91
	/*
92
	 * (non-PHPdoc)
93
	 * @see BaseHtml::run()
94
	 */
95
	public function run(JsUtils $js) {
96 View Code Duplication
		if (isset($this->_bsComponent) === false)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
97
			$this->_bsComponent=$js->semantic()->progress("#" . $this->identifier, $this->_params);
98
		$this->addEventsOnRun($js);
99
		return $this->_bsComponent;
100
	}
101
}