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

MenuItemTrait::asHeader()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 2
1
<?php
2
namespace Ajax\semantic\html\base\traits;
3
4
use Ajax\service\JArray;
5
use Ajax\service\JString;
6
use Ajax\semantic\html\elements\HtmlInput;
7
use Ajax\semantic\html\base\constants\Direction;
8
9
trait MenuItemTrait {
10
11
	public function setContent($content){
12
		if($content==="-"){
13
			$this->asDivider();
14
		}elseif($content==="-search-"){
15
			$values=\explode(",",$content,-1);
16
			$this->asSearchInput(JArray::getDefaultValue($values, 0, "Search..."),JArray::getDefaultValue($values, 1, "search"));
17
		}elseif(JString::startswith($content, "-")){
18
			$content=\ltrim($content,"-");
19
			$this->asHeader($content);
20
		}else
21
			parent::setContent($content);
22
		return $this;
23
	}
24
25
	/**
26
	 * @param string $placeholder
27
	 * @param string $icon
28
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem|\Ajax\semantic\html\content\HtmlMenuItem
29
	 */
30
	public function asSearchInput($placeholder=NULL,$icon=NULL){
31
		$this->setClass("ui icon search input");
0 ignored issues
show
Bug introduced by
It seems like setClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
32
		$input=new HtmlInput("search-".$this->identifier);
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...
33
		if(isset($placeholder))
34
			$input->setProperty("placeholder", $placeholder);
35
			$this->content=$input;
0 ignored issues
show
Bug introduced by
The property content 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...
36
			if(isset($icon))
37
				$this->addIcon($icon);
0 ignored issues
show
Bug introduced by
It seems like addIcon() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
38
				return $this;
39
	}
40
41
	/**
42
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem|\Ajax\semantic\html\content\HtmlMenuItem
43
	 */
44
	public function asDivider(){
45
		$this->content=NULL;
46
		$this->tagName="div";
0 ignored issues
show
Bug introduced by
The property tagName 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...
47
		$this->setClass("divider");
0 ignored issues
show
Bug introduced by
It seems like setClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
48
		return $this;
49
	}
50
51
	/**
52
	 * @param string $caption
53
	 * @param string $icon
54
	 * @return \Ajax\semantic\html\content\HtmlDropdownItem|\Ajax\semantic\html\content\HtmlMenuItem
55
	 */
56
	public function asHeader($caption=NULL,$icon=NULL){
57
		$this->setClass("header");
0 ignored issues
show
Bug introduced by
It seems like setClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
58
		$this->tagName="div";
59
		$this->content=$caption;
60
		if(isset($icon))
61
			$this->addIcon($icon,Direction::LEFT);
0 ignored issues
show
Bug introduced by
It seems like addIcon() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
62
			return $this;
63
	}
64
}