Completed
Push — master ( fdc0c0...9de830 )
by Jean-Christophe
03:31
created

HtmlAccordion   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 5.88 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createItem() 0 9 2
A createCondition() 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\HtmlSemCollection;
6
use Ajax\semantic\html\content\HtmlAccordionItem;
7
use Ajax\JsUtils;
8
9
class HtmlAccordion extends HtmlSemCollection{
10
11
	protected $params=array();
12
13
	public function __construct( $identifier, $tagName="div", $baseClass="ui"){
14
		parent::__construct( $identifier, "div", "ui accordion");
15
	}
16
17
18
	protected function createItem($value){
19
		$count=$this->count();
20
		$title=$value;
21
		$content=NULL;
22
		if(\is_array($value)){
23
			$title=@$value[0];$content=@$value[1];
24
		}
25
		return new HtmlAccordionItem("item-".$this->identifier."-".$count, $title,$content);
26
	}
27
28
	protected function createCondition($value){
29
		return ($value instanceof HtmlAccordionItem)===false;
30
	}
31
32
	/*
33
	 * (non-PHPdoc)
34
	 * @see BaseHtml::run()
35
	 */
36
	public function run(JsUtils $js) {
37 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...
38
			$this->_bsComponent=$js->semantic()->accordion("#".$this->identifier,$this->params);
39
			$this->addEventsOnRun($js);
40
			return $this->_bsComponent;
41
	}
42
}