Completed
Push — master ( b77ba2...042f42 )
by Jean-Christophe
03:22
created

NavElementTrait::fromDispatcher()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
namespace Ajax\common\html\traits;
3
use Ajax\JsUtils;
4
5
trait NavElementTrait{
6
	/**
7
	 * Generate the jquery script to set the elements to the HtmlNavElement
8
	 * @param JsUtils $jsUtils
9
	 */
10
	public function jsSetContent(JsUtils $jsUtils){
11
		$jsUtils->html("#".$this->identifier,str_replace("\"","'", $this->contentAsString()),true);
0 ignored issues
show
Bug introduced by
The property identifier does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Documentation Bug introduced by
The method contentAsString does not exist on object<Ajax\common\html\traits\NavElementTrait>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
12
	}
13
14
	public function getRoot() {
15
		return $this->root;
0 ignored issues
show
Bug introduced by
The property root does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
	}
17
	public function setRoot($root) {
18
		$this->root = $root;
19
		return $this;
20
	}
21
	public function getAttr() {
22
		return $this->attr;
0 ignored issues
show
Bug introduced by
The property attr does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
	}
24
25
	/**
26
	 * Define the html attribute for each element url in ajax
27
	 * @param string $attr html attribute
28
	 * @return HtmlNavElement
29
	 */
30
	public function setAttr($attr) {
31
		$this->attr = $attr;
32
		return $this;
33
	}
34
35
	public function __call($method, $args) {
36
		if(isset($this->$method) && is_callable($this->$method)) {
37
			return call_user_func_array(
38
					$this->$method,
39
					$args
40
					);
41
		}
42
	}
43
44
	abstract public function fromDispatcher(JsUtils $js,$dispatcher,$startIndex=0);
45
}