Completed
Push — master ( 172c54...50fc65 )
by Jean-Christophe
04:31 queued 01:31
created

InternalPopup::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 5
1
<?php
2
3
namespace Ajax\semantic\html\content;
4
5
use Ajax\JsUtils;
6
use Ajax\service\JString;
7
use Ajax\semantic\html\base\HtmlSemDoubleElement;
8
class InternalPopup {
9
	protected $title;
10
	protected $content;
11
	protected $html;
12
	protected $variation;
13
	protected $params;
14
	protected $semElement;
15
	public function __construct($semElement,$title="",$content="",$variation=NULL,$params=array()){
16
		$this->semElement=$semElement;
17
		$this->title=$title;
18
		$this->content=$content;
19
		$this->setAttributes($variation,$params);
20
	}
21
22
	public function setHtml($html) {
23
		$this->html= $html;
24
		return $this;
25
	}
26
27
	public function setAttributes($variation=NULL,$params=array()){
28
		$this->variation=$variation;
29
		$this->params=$params;
30
	}
31
32
	public function onShow($jsCode){
33
		$this->params["onShow"]=$jsCode;
34
	}
35
36
	public function compile(JsUtils $js=NULL){
37
		if(JString::isNotNull($this->title)){
38
			$this->semElement->addToProperty("data-title", $this->title);
39
		}
40
		if(JString::isNotNull($this->content)){
41
			$this->semElement->addToProperty("data-content", $this->content);
42
		}
43
		if(JString::isNotNull($this->html)){
44
			$html=$this->html;
45
			if(\is_array($html)){
46
				\array_walk($html, function(&$item) use($js){
47
					if($item instanceof HtmlSemDoubleElement){
48
						$comp=$item->compile($js);
49
						$bs=$item->run($js);
0 ignored issues
show
Bug introduced by
It seems like $js defined by parameter $js on line 36 can be null; however, Ajax\semantic\html\base\...SemDoubleElement::run() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
50
						if(isset($bs))
51
							$this->params['onShow']=$bs->getScript();
52
						$item=$comp;
53
					}
54
				});
55
				$html=\implode("",$html);
56
			}
57
			$html=\str_replace("\"", "'", $html);
58
			$this->semElement->addToProperty("data-html", $html);
59
		}
60
		if(JString::isNotNull($this->variation)){
61
			$this->semElement->addToProperty("data-variation", $this->variation);
62
		}
63
	}
64
65
	public function run(JsUtils $js){
66
		$js->semantic()->popup("#".$this->semElement->getIdentifier(),$this->params);
67
	}
68
69
}