Completed
Push — master ( 506112...a79a4a )
by Jean-Christophe
02:53
created

CheckboxTrait::setChecked()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\collections\form\traits;
4
5
use Ajax\semantic\html\base\constants\CheckboxType;
6
use Ajax\semantic\html\modules\checkbox\AbstractCheckbox;
7
8
trait CheckboxTrait {
9
10
	public abstract function addToPropertyCtrl($name, $value, $typeCtrl);
11
12
	public function setType($checkboxType) {
13
		return $this->getHtmlCk()->addToPropertyCtrl("class", $checkboxType, CheckboxType::getConstants());
14
	}
15
16
17
	/**
18
	 * Attach $this to $selector and fire $action
19
	 * @param string $selector jquery selector of the associated element
20
	 * @param string $action action to execute : check, uncheck or NULL for toggle
21
	 * @return \Ajax\semantic\html\collections\form\AbstractHtmlFormRadioCheckbox
22
	 */
23
	public function attachEvent($selector, $action=NULL) {
24
		return $this->getHtmlCk()->attachEvent($selector, $action);
25
	}
26
27
	/**
28
	 * Attach $this to an array of $action=>$selector
29
	 * @param array $events associative array of events to attach ex : ["#bt-toggle","check"=>"#bt-check","uncheck"=>"#bt-uncheck"]
30
	 * @return \Ajax\semantic\html\collections\form\AbstractHtmlFormRadioCheckbox
31
	 */
32
	public function attachEvents($events=array()) {
33
		return $this->getHtmlCk()->attachEvents($events);
34
	}
35
36
	public function getField(){
37
		return $this->content["field"]->getField();
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...
38
	}
39
40
	public function getHtmlCk(){
41
		return $this->content["field"];
42
	}
43
44
	public function getDataField(){
45
		$field= $this->getField();
46
		if($field instanceof AbstractCheckbox)
47
			$field=$field->getField();
48
			return $field;
49
	}
50
51
	/**
52
	 * Check the checkbox
53
	 * @param boolean $value
54
	 * @return \Ajax\semantic\html\collections\form\traits\CheckboxTrait
0 ignored issues
show
Comprehensibility Bug introduced by
The return type CheckboxTrait is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
55
	 */
56 View Code Duplication
	public function setChecked($value=true){
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...
57
		if($value===true){
58
			$this->getDataField()->setProperty("checked", "checked");
59
		}else{
60
			$this->getDataField()->removeProperty("checked");
61
		}
62
		return $this;
63
	}
64
65
}