HtmlSplitbutton   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 25 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setSize() 0 6 2
A onButtonClick() 0 3 1
A __construct() 0 6 1
A run() 10 10 3

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\bootstrap\html;
4
5
use Ajax\bootstrap\html\HtmlDropdown;
6
use Ajax\bootstrap\html\base\CssRef;
7
use Ajax\JsUtils;
8
9
/**
10
 * Twitter Bootstrap HTML Splitbutton component
11
 * @author jc
12
 * @version 1.001
13
 */
14
class HtmlSplitbutton extends HtmlDropdown {
15
16
	public function __construct($identifier, $value="&nbsp;", $items=array(), $cssStyle="btn-default", $onClick=null) {
17
		parent::__construct($identifier, $value, $items, $cssStyle, $onClick);
18
		$this->asButton($cssStyle);
19
		$this->_template=include 'templates/tplSplitbutton.php';
20
		$this->mClass="btn-group";
21
	}
22
23
	/**
24
	 * (non-PHPdoc)
25
	 * @see \Ajax\bootstrap\html\HtmlDropdown::setSize()
26
	 * @return HtmlSplitbutton
27
	 */
28
	public function setSize($size) {
29
		if (is_int($size)) {
30
			return $this->addToMember($this->mClass, CssRef::sizes("btn-group")[$size]);
31
		}
32
		return $this->addToMemberCtrl($this->mClass, $size, CssRef::sizes("btn-group"));
33
	}
34
35
	public function onButtonClick($jsCode) {
36
		$this->addEvent("buttonClick", $jsCode);
37
	}
38
39
	/*
40
	 * (non-PHPdoc)
41
	 * @see BaseHtml::run()
42
	 */
43 View Code Duplication
	public function run(JsUtils $js) {
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...
44
		if ($this->getProperty("role")==="nav") {
45
			foreach ( $this->items as $dropdownItem ) {
46
				$dropdownItem->runNav($js);
47
			}
48
		}
49
		$this->_bsComponent=$js->bootstrap()->splitbutton("#".$this->identifier);
50
		$this->addEventsOnRun($js);
51
		return $this->_bsComponent;
52
	}
53
}