Passed
Push — master ( 3c6756...8b3b37 )
by Michael
20:43 queued 12:59
created

CheckboxField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 16
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderBody() 0 9 3
A init() 0 3 2
1
<?php
2
	/**
3
	 * @package Demos
4
	 */
5
	class CheckboxField extends Field
6
	{
7
		function init($request)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8
		{
9
			$this->value = $request->get($this->name, $this->default ? '1' : null) === '1';
10
		}
11
		
12
		function renderBody($name, $id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
13
		{
14
			if ($this->value)
15
				$chk = 'checked="checked"';
16
			else
17
				$chk = '';
18
			
19
			echo '<input type="hidden" name="' . $name . '" id="' . $id . '_val" value="' . ($this->value ? '1' : '') . '" />';
20
			echo '<input type="checkbox" ' . $chk . ' name="' . $name . '_cb" id="' . $id . '" value="1" onclick="document.getElementById(\'' . $id . '_val\').value = Number(this.checked);" />';
21
		}
22
	}
23