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

Checkbox   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A render() 0 3 1
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
}