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

HtmlCollection::addItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
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
}