Completed
Push — master ( 19ac8a...195df7 )
by Jean-Christophe
03:23
created

HtmlCollection   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 63
Duplicated Lines 12.7 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addItems() 0 5 2
A setItems() 0 4 1
A getItems() 0 3 1
A addItem() 0 8 2
A getItem() 8 8 2
A setItem() 0 4 1
A count() 0 3 1
createItem() 0 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\common\html\html5;
4
5
use Ajax\common\html\HtmlDoubleElement;
6
7
abstract class HtmlCollection extends HtmlDoubleElement {
8
	public function __construct($identifier,$tagName="div"){
9
		parent::__construct($identifier,$tagName);
10
		$this->content=array();
11
	}
12
13
	public function addItems($items){
14
		foreach ($items as $item){
15
			$this->addItem($item);
16
		}
17
	}
18
19
	public function setItems($items){
20
		$this->content=$items;
21
		return $this;
22
	}
23
24
	public function getItems(){
25
		return $this->content;
26
	}
27
28
	/**
29
	 * adds and returns an item
30
	 * @param HtmlDoubleElement|string $item
31
	 * @return \Ajax\common\html\HtmlDoubleElement
32
	 */
33
	public function addItem($item){
34
		$itemO=$item;
35
		if(\is_string($item)){
36
			$itemO=$this->createItem($item);
37
		}
38
		$this->addContent($itemO);
39
		return $itemO;
40
	}
41
42
	/**
43
	 * Return the item at index
44
	 * @param int|string $index the index or the item identifier
45
	 * @return \Ajax\common\html\HtmlDoubleElement
46
	 */
47 View Code Duplication
	public function getItem($index) {
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...
48
		if (is_int($index))
49
			return $this->content[$index];
50
		else {
51
			$elm=$this->getElementById($index, $this->content);
52
			return $elm;
53
		}
54
	}
55
56
	public function setItem($index, $value) {
57
		$this->content[$index]=$value;
58
		return $this;
59
	}
60
61
	public function count(){
62
		return \sizeof($this->content);
63
	}
64
	/**
65
	 * The item factory
66
	 * @param string|HtmlDoubleElement $value
67
	 */
68
	protected abstract function createItem($value);
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
69
}