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

HtmlFormField   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 11.29 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A setLabel() 0 9 2
A setField() 0 3 1
A getLabel() 0 4 2
A getField() 0 3 1
A swapLabel() 0 5 1
A setWidth() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}