Completed
Push — master ( 424d4e...c1a616 )
by Jean-Christophe
03:24
created

HtmlSemNavElement::setDivider()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
1
<?php
2
namespace Ajax\semantic\html\base;
3
4
use Ajax\JsUtils;
5
use Ajax\service\JArray;
6
/**
7
 * Sem class for navigation elements : Breadcrumbs and Pagination
8
 * @author jc
9
 * @version 1.001
10
 */
11
abstract class HtmlSemNavElement extends HtmlSemCollection {
12
	/**
13
	 * @var string the root site
14
	 */
15
	protected $root;
16
17
	/**
18
	 * @var String the html attribute which contains the elements url. default : data-ajax
19
	 */
20
	protected $attr;
21
22
	protected $_contentSeparator="";
23
24
25
	public function __construct($identifier,$tagName,$baseClass){
26
		parent::__construct($identifier,$tagName,$baseClass);
27
		$this->root="";
28
		$this->attr="data-ajax";
29
	}
30
31
	/**
32
	 * Associate an ajax get to the elements, displayed in $targetSelector
33
	 * $attr member is used to build each element url
34
	 * @param string $targetSelector the target of the get
35
	 * @param string $attr the html attribute used to build the elements url
0 ignored issues
show
Bug introduced by
There is no parameter named $attr. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
36
	 * @return HtmlNavElement
37
	 */
38
	public function autoGetOnClick($targetSelector){
39
		return $this->getOnClick($this->root, $targetSelector,array("attr"=>$this->attr));
40
	}
41
42
	public function contentAsString(){
43
		return JArray::implode($this->_contentSeparator, $this->content);
44
	}
45
46
	/**
47
	 * Generate the jquery script to set the elements to the HtmlNavElement
48
	 * @param JsUtils $jsUtils
49
	 */
50
	public function jsSetContent(JsUtils $jsUtils){
51
		$jsUtils->html("#".$this->identifier,str_replace("\"","'", $this->contentAsString()),true);
52
	}
53
54
	public function getRoot() {
55
		return $this->root;
56
	}
57
	public function setRoot($root) {
58
		$this->root = $root;
59
		return $this;
60
	}
61
	public function getAttr() {
62
		return $this->attr;
63
	}
64
65
	/**
66
	 * Define the html attribute for each element url in ajax
67
	 * @param string $attr html attribute
68
	 * @return HtmlNavElement
69
	 */
70
	public function setAttr($attr) {
71
		$this->attr = $attr;
72
		return $this;
73
	}
74
75 View Code Duplication
	public function __call($method, $args) {
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...
76
		if(isset($this->$method) && is_callable($this->$method)) {
77
			return call_user_func_array(
78
					$this->$method,
79
					$args
80
					);
81
		}
82
	}
83
84
	public abstract function fromDispatcher($dispatcher,$startIndex=0);
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
85
86
87
	public function setContentDivider($divider,$index=NULL) {
88
		$divider="<div class='divider'> {$divider} </div>";
89
		return $this->setDivider($divider, $index);
90
	}
91
92
	public function setIconContentDivider($iconContentDivider,$index=NULL) {
93
		$contentDivider="<i class='".$iconContentDivider." icon divider'></i>";
94
		return $this->setDivider($contentDivider, $index);
95
	}
96
97
	protected function setDivider($divider,$index){
98
		if(isset($index)){
99
			if(\is_array($this->_contentSeparator)===false)
100
				$this->_contentSeparator=array_fill (0, $this->count()-1,$this->_contentSeparator);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_fill(0, $this->cou...his->_contentSeparator) of type array is incompatible with the declared type string of property $_contentSeparator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
101
			$this->_contentSeparator[$index]=$divider;
102
		}else{
103
			$this->_contentSeparator=$divider;
104
		}
105
		return $this;
106
	}
107
108
	protected function getContentDivider($index){
109
		if(\is_array($this->_contentSeparator)===true){
110
			return @$this->_contentSeparator[$index];
111
		}
112
		return $this->_contentSeparator;
113
	}
114
115
116
}