Passed
Push — master ( ef71b3...70921f )
by Jean-Christophe
02:06
created

HtmlDoubleElement::asLink()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Ajax\common\html;
4
5
6
use Ajax\JsUtils;
7
class HtmlDoubleElement extends HtmlSingleElement {
8
	/**
9
	 *
10
	 * @var mixed
11
	 */
12
	protected $content;
13
	protected $wrapContentBefore="";
14
	protected $wrapContentAfter="";
15
16
	public function __construct($identifier, $tagName="p") {
17
		parent::__construct($identifier, $tagName);
18
		$this->_template='<%tagName% id="%identifier%" %properties%>%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>';
19
	}
20
21
	public function setContent($content) {
22
		$this->content=$content;
23
		return $this;
24
	}
25
26
	public function getContent() {
27
		return $this->content;
28
	}
29
30
	public function addContent($content,$before=false) {
31
		if (!\is_array($this->content)) {
32
			if(isset($this->content))
33
				$this->content=array ($this->content);
34
			else
35
				$this->content=array();
36
		}
37
		if($before)
38
			array_unshift($this->content,$content);
39
		else
40
			$this->content []=$content;
41
		return $this;
42
	}
43
44
	/*
45
	 * (non-PHPdoc)
46
	 * @see \Ajax\bootstrap\html\HtmlSingleElement::run()
47
	 */
48
	public function run(JsUtils $js) {
49
		parent::run($js);
50
		if ($this->content instanceof HtmlDoubleElement) {
51
			$this->content->run($js);
52
		} else if (\is_array($this->content)) {
53
			foreach ( $this->content as $itemContent ) {
54
				if ($itemContent instanceof HtmlDoubleElement) {
55
					$itemContent->run($js);
56
				}
57
			}
58
		}
59
	}
60
61
	public function setValue($value) {
1 ignored issue
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

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

61
	public function setValue(/** @scrutinizer ignore-unused */ $value) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
	}
63
64
	public function wrapContent($before, $after="") {
65
		$this->wrapContentBefore.=$before;
66
		$this->wrapContentAfter=$after.$this->wrapContentAfter;
67
		return $this;
68
	}
69
70
	public function getContentInstances($class){
71
		return $this->_getContentInstances($class,$this->content);
72
	}
73
74
	protected function _getContentInstances($class,$content){
75
		$instances=[];
76
		if($content instanceof $class){
77
			$instances[]=$content;
78
		}elseif($content instanceof HtmlDoubleElement){
79
			$instances=\array_merge($instances,$content->getContentInstances($class));
1 ignored issue
show
Bug introduced by
Are you sure the usage of $content->getContentInstances($class) targeting Ajax\common\html\HtmlDou...::getContentInstances() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
80
		}elseif (\is_array($content)){
81
			foreach ($content as $element){
82
				$instances=\array_merge($instances,$this->_getContentInstances($class, $element));
83
			}
84
		}
85
		return $instances;
86
	}
87
88
	/**
89
	 * Transforms the element into a link
90
	 * @return HtmlDoubleElement
91
	 */
92
	public function asLink($href=NULL,$target=NULL) {
93
		if (isset($href))
94
			$this->setProperty("href", $href);
95
		if(isset($target))
96
			$this->setProperty("target", $target);
97
		return $this->setTagName("a");
98
	}
99
}
100