Completed
Push — master ( 79b035...e37d9a )
by Jean-Christophe
03:44
created

FieldsTrait::createItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\collections\form\traits;
4
5
use Ajax\service\JArray;
6
use Ajax\semantic\html\collections\form\HtmlFormInput;
7
use Ajax\semantic\html\collections\form\HtmlFormDropdown;
8
use Ajax\semantic\html\elements\HtmlButton;
9
use Ajax\semantic\html\collections\form\HtmlFormCheckbox;
10
use Ajax\semantic\html\collections\form\HtmlFormRadio;
11
trait FieldsTrait {
12
	protected function createItem($value){
13
		if(\is_array($value)){
14
			$itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null)));
15
			return $itemO;
16
		}else
17
			return new HtmlFormInput($value);
18
	}
19
20
	public function addInputs($inputs,$fieldslabel=null){
21
		$fields=array();
22
		foreach ($inputs as $input){
23
			\extract($input);
24
			$f=new HtmlFormInput("","");
25
			$f->fromArray($input);
26
			$fields[]=$f;
27
		}
28
		return $this->addFields($fields,$fieldslabel);
0 ignored issues
show
Bug introduced by
It seems like addFields() 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...
29
	}
30
31
	/**
32
	 * @param string $identifier
33
	 * @param array $items
34
	 * @param string $label
35
	 * @param string $value
36
	 * @param string $multiple
37
	 * @return \Ajax\common\html\HtmlDoubleElement
38
	 */
39
	public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){
40
		return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple));
0 ignored issues
show
Bug introduced by
It seems like $multiple defined by parameter $multiple on line 39 can also be of type string; however, Ajax\semantic\html\colle...Dropdown::__construct() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like addItem() 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...
41
	}
42
43
	public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL){
44
		return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder));
0 ignored issues
show
Bug introduced by
It seems like addItem() 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...
45
	}
46
47
	public function addButton($identifier,$value,$cssStyle=NULL,$onClick=NULL){
48
		return $this->addItem(new HtmlButton($identifier,$value,$cssStyle,$onClick));
0 ignored issues
show
Bug introduced by
It seems like addItem() 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...
49
	}
50
51
	public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){
52
		return $this->addItem(new HtmlFormCheckbox($identifier,$label,$value,$type));
0 ignored issues
show
Bug introduced by
It seems like addItem() 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...
53
	}
54
55
	public function addRadio($identifier, $name,$label=NULL,$value=NULL){
56
		return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value));
0 ignored issues
show
Bug introduced by
It seems like addItem() 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...
57
	}
58
}