Passed
Push — master ( fdcf95...dcc4d7 )
by Jean-Christophe
03:10
created

HtmlInput   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 42
rs 10
c 1
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setInputType() 0 2 1
A __construct() 0 6 1
A compile() 0 8 3
A setValue() 0 4 2
A forceValue() 0 4 1
A setPlaceholder() 0 4 2
1
<?php
2
namespace Ajax\common\html\html5;
3
4
use Ajax\common\html\HtmlSingleElement;
5
use Ajax\service\JString;
6
use Ajax\JsUtils;
7
8
class HtmlInput extends HtmlSingleElement {
9
10
	protected $_placeholder;
11
12
	public function __construct($identifier, $type = "text", $value = NULL, $placeholder = NULL) {
13
		parent::__construct($identifier, "input");
14
		$this->setProperty("name", $identifier);
15
		$this->setValue($value);
16
		$this->setPlaceholder($placeholder);
17
		$this->setProperty("type", $type);
18
	}
19
20
	public function setValue($value) {
21
		if (isset($value))
22
			$this->setProperty("value", $value);
23
		return $this;
24
	}
25
26
	public function setInputType($value) {
27
		return $this->setProperty("type", $value);
28
	}
29
30
	public function forceValue($value = 'true') {
31
		$this->wrap('<input type="hidden" value="false" name="' . $this->identifier . '"/>');
32
		$this->setValue($value);
33
		return $this;
34
	}
35
36
	public function setPlaceholder($value) {
37
		if (JString::isNotNull($value))
38
			$this->_placeholder = $value;
39
		return $this;
40
	}
41
42
	public function compile(JsUtils $js = NULL, &$view = NULL) {
43
		$value = $this->_placeholder;
44
		if (JString::isNull($value)) {
45
			if (JString::isNotNull($this->getProperty("name")))
46
				$value = \ucfirst($this->getProperty("name"));
47
		}
48
		$this->setProperty("placeholder", $value);
49
		return parent::compile($js, $view);
50
	}
51
}
52