Completed
Push — master ( 916f6f...ea2a7d )
by Jean-Christophe
03:42
created

CheckboxTrait::attachEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Ajax\semantic\html\collections\form\traits;
4
5
use Ajax\semantic\html\base\constants\CheckboxType;
6
7
trait CheckboxTrait {
8
9
	public abstract function addToPropertyCtrl($name, $value, $typeCtrl);
10
11
	public function setType($checkboxType) {
12
		return $this->addToPropertyCtrl("class", $checkboxType, CheckboxType::getConstants());
13
	}
14
15
	/**
16
	 * Attach $this to $selector and fire $action
17
	 * @param string $selector jquery selector of the associated element
18
	 * @param string $action action to execute : check, uncheck or NULL for toggle
19
	 * @return \Ajax\semantic\html\collections\form\AbstractHtmlFormRadioCheckbox
20
	 */
21
	public function attachEvent($selector, $action=NULL) {
22
		return $this->getField()->attachEvent($selector, $action);
0 ignored issues
show
Bug introduced by
It seems like getField() 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...
23
	}
24
25
	/**
26
	 * Attach $this to an array of $action=>$selector
27
	 * @param array $events associative array of events to attach ex : ["#bt-toggle","check"=>"#bt-check","uncheck"=>"#bt-uncheck"]
28
	 * @return \Ajax\semantic\html\collections\form\AbstractHtmlFormRadioCheckbox
29
	 */
30
	public function attachEvents($events=array()) {
31
		return $this->getField()->attachEvents($events);
0 ignored issues
show
Bug introduced by
It seems like getField() 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...
32
	}
33
}