Completed
Push — master ( 15db70...750821 )
by Dennis
01:29
created

Checkbox::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace lloc\Msls\Component\Input;
4
5
use lloc\Msls\Component\InputInterface;
6
7
/**
8
 * Class Checkbox
9
 * @package lloc\Msls\Component\Input
10
 */
11
class Checkbox implements InputInterface {
12
13
	/**
14
	 * @var string
15
	 */
16
	protected $key;
17
18
	/**
19
	 * @var string
20
	 */
21
	protected $selected;
22
23
	/**
24
	 * @param string $key
25
	 * @param string|null $value
26
	 */
27
	public function __construct( string $key, $value ) {
28
		$this->key      = esc_attr( $key );
29
		$this->selected	= checked( 1, $value, false );
30
	}
31
32
	/**
33
	 * @return string
34
	 */
35
	public function render(): string {
36
		return sprintf('<input type="checkbox" id="%1$s" name="msls[%1$s]" value="1" %2$s/>', $this->key, $this->selected );
37
	}
38
39
}