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

IconTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addIcon() 0 16 3
A getIcon() 0 8 4
1
<?php
2
3
namespace Ajax\semantic\html\base\traits;
4
5
use Ajax\semantic\html\elements\HtmlIcon;
6
use Ajax\semantic\html\base\constants\Direction;
7
trait IconTrait {
8
	private $_hasIcon=false;
9
10
	public function addIcon($icon,$direction=Direction::LEFT){
11
		if($this->_hasIcon===false){
12
			$iconO=$icon;
13
			if(\is_string($icon)){
14
				$iconO=new HtmlIcon("icon-".$this->identifier, $icon);
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...
15
			}
16
			$this->addToPropertyCtrl("class", $direction." icon", Direction::getConstantValues("icon"));
0 ignored issues
show
Bug introduced by
It seems like addToPropertyCtrl() 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...
17
			$this->addContent($iconO,false);
0 ignored issues
show
Bug introduced by
It seems like addContent() 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...
18
			$this->_hasIcon=true;
19
		}else{
20
			$iconO=$this->getIcon();
21
			$iconO->setIcon($icon);
22
			$this->addToPropertyCtrl("class", $direction." icon", Direction::getConstantValues("icon"));
0 ignored issues
show
Bug introduced by
It seems like addToPropertyCtrl() 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...
23
		}
24
		return $iconO;
25
	}
26
27
	public function getIcon(){
28
		if(\is_array($this->content)){
29
			foreach ($this->content as $item){
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...
30
				if($item instanceof HtmlIcon)
31
					return $item;
32
			}
33
		}
34
	}
35
}