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

HtmlViewGroups   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createItem() 0 18 4
A setWide() 0 3 1
A getItem() 0 2 1
A fromDatabaseObject() 0 2 1
A getItemContent() 0 4 2
A run() 0 3 1
1
<?php
2
3
namespace Ajax\semantic\html\content\view;
4
5
use Ajax\semantic\html\base\HtmlSemCollection;
6
use Ajax\service\JArray;
7
use Ajax\semantic\html\base\constants\Wide;
8
use Ajax\JsUtils;
9
10
abstract class HtmlViewGroups extends HtmlSemCollection {
11
12
	public function __construct($identifier, $uiClass,$items=array()) {
13
		parent::__construct($identifier, "div", $uiClass);
14
		$this->addItems($items);
15
	}
16
17
	abstract protected function createElement();
18
19
	protected function createItem($value) {
20
		$result=$this->createElement();
21
		if (\is_array($value)) {
22
			$header=JArray::getValue($value, "header", 0);
23
			$metas=JArray::getValue($value, "metas", 1);
24
			$description=JArray::getValue($value, "description", 2);
25
			$image=JArray::getValue($value, "image", 3);
26
			$extra=JArray::getValue($value, "extra", 4);
27
			if (isset($image)) {
28
				$result->addImage($image);
29
			}
30
			$result->addItemHeaderContent($header, $metas, $description);
31
			if (isset($extra)) {
32
				$result->addExtraContent($extra);
33
			}
34
		} else
35
			$result->addItemContent($value);
36
		return $result;
37
	}
38
39
	/**
40
	 * Defines the ites width (alias for setWidth)
41
	 * @param int $wide
42
	 */
43
	public function setWide($wide) {
44
		$wide=Wide::getConstants()["W" . $wide];
45
		return $this->addToPropertyCtrl("class", $wide, Wide::getConstants());
46
	}
47
48
	abstract public function newItem($identifier);
49
50
	/**
51
	 * @return HtmlViewGroups
52
	 */
53
	public function getItem($index){
54
		return parent::getItem($index);
55
	}
56
57
	public function getItemContent($itemIndex, $contentIndex) {
58
		$item=$this->getItem($itemIndex);
59
		if (isset($item)) {
60
			return $item->getItemContent($contentIndex);
0 ignored issues
show
Bug introduced by
The call to Ajax\semantic\html\conte...roups::getItemContent() has too few arguments starting with contentIndex. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
			return $item->/** @scrutinizer ignore-call */ getItemContent($contentIndex);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
61
		}
62
	}
63
64
	public function fromDatabaseObject($object, $function) {
65
		return $this->addItem($function($object));
66
	}
67
68
	public function run(JsUtils $js){
69
		$result=parent::run($js);
70
		return $result->setItemSelector(".item");
71
	}
72
}
73