Passed
Push — master ( d75a73...4a339e )
by Jean-Christophe
02:07
created

HtmlIconGroups   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toCorner() 0 3 1
A run() 0 3 1
A corner() 0 3 1
A createItem() 0 11 3
A getIcon() 0 2 1
A createCondition() 0 2 1
A getItem() 0 2 1
1
<?php
2
3
namespace Ajax\semantic\html\elements;
4
5
use Ajax\semantic\html\base\HtmlSemCollection;
6
use Ajax\service\JArray;
7
use Ajax\JsUtils;
8
9
/**
10
 * Semantic Icons group component
11
 * @see http://phpmv-ui.kobject.net/index/direct/main/72
12
 * @see http://semantic-ui.com/elements/icon.html#/definition
13
 * @author jc
14
 * @version 1.001
15
 */
16
class HtmlIconGroups extends HtmlSemCollection {
17
18
	public function __construct($identifier, $icons=array(), $size="") {
19
		parent::__construct($identifier, "i", "icons");
20
		$this->addItems($icons);
21
		$this->setSize($size);
22
	}
23
	
24
	/**
25
	 * @return HtmlIcon
26
	 */
27
	public function getItem($index){
28
		return parent::getItem($index);
29
	}
30
31
	protected function createItem($value) {
32
		$icon=$value;
33
		if (\is_array($value)) {
34
			$icon=JArray::getValue($value, "icon", 0);
35
			$size=JArray::getValue($value, "size", 1);
36
		}
37
		$iconO=new HtmlIcon("icon-" . $this->identifier, $icon);
38
		if (isset($size)) {
39
			$iconO->setSize($size);
40
		}
41
		return $iconO;
42
	}
43
44
	protected function createCondition($value) {
45
		return ($value instanceof HtmlIcon) === false;
46
	}
47
48
	public function getIcon($index) {
49
		return $this->content[$index];
50
	}
51
52
	public function run(JsUtils $js){
53
		$result= parent::run($js);
54
		return $result->setItemSelector("i");
55
	}
56
57
	public function toCorner($index=1) {
58
		$this->getItem($index)->toCorner();
59
		return $this;
60
	}
61
62
	public static function corner($mainIcon,$cornerIcon,$size="huge"){
63
		$icons=new HtmlIconGroups("icons",[$mainIcon,$cornerIcon],$size);
64
		return $icons->toCorner(1);
65
	}
66
}
67