Completed
Push — master ( b49918...3cf661 )
by Jean-Christophe
03:33
created

HtmlFormField::getLabel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace Ajax\semantic\html\collections\form;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\semantic\html\base\constants\Wide;
7
8
class HtmlFormField extends HtmlSemDoubleElement {
9
	public function __construct($identifier, $field,$label=NULL) {
10
		parent::__construct($identifier, "div","field");
11
		$this->content=array();
12
		if(isset($label))
13
			$this->setLabel($label);
14
		$this->setField($field);
15
	}
16
17
	public function setLabel($label){
18
		$labelO=$label;
19
		if(\is_string($label)){
20
			$labelO=new HtmlSemDoubleElement("","label");
21
			$labelO->setContent($label);
22
			$labelO->setProperty("for", \str_replace("field-", "",$this->identifier));
23
		}
24
		$this->content["label"]=$labelO;
25
	}
26
27
	public function setField($field){
28
		$this->content["field"]=$field;
29
	}
30
31
	/**
32
	 * Returns the label or null
33
	 * @return mixed
34
	 */
35
	public function getLabel(){
36
		if(\array_key_exists("label", $this->content))
37
			return $this->content["label"];
38
	}
39
40
	/**
41
	 * Return the field
42
	 * @return mixed
43
	 */
44
	public function getField(){
45
		return $this->content["field"];
46
	}
47
48
	/**
49
	 * puts the label before or behind
50
	 */
51
	public function swapLabel(){
52
		$label=$this->getLabel();
53
		unset($this->content["label"]);
54
		$this->content["label"]=$label;
55
	}
56
57
	/**
58
	 * Defines the field width
59
	 * @param int $width
60
	 * @return \Ajax\semantic\html\collections\form\HtmlFormField
61
	 */
62 View Code Duplication
	public function setWidth($width){
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...
63
		if(\is_int($width)){
64
			$width=Wide::getConstants()["W".$width];
65
		}
66
		$this->addToPropertyCtrl("class", $width, Wide::getConstants());
67
		return $this->addToPropertyCtrl("class", "wide",array("wide"));
68
	}
69
}