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

Option::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 5
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 Option
9
 * @package lloc\Msls\Component\Input
10
 */
11
class Option implements InputInterface {
12
13
	/**
14
	 * @var string
15
	 */
16
	protected $key;
17
18
	/**
19
	 * @var string
20
	 */
21
	protected $value;
22
23
	/**
24
	 * @var string
25
	 */
26
	protected $selected;
27
28
	/**
29
	 * @param string $key
30
	 * @param string|null $value
31
	 * @param string|null $selected
32
	 */
33
	public function __construct( string $key, $value, $selected = null ) {
34
		$this->key      = esc_attr( $key );
35
		$this->value    = esc_attr( $value );
36
		$this->selected = selected( $key, esc_attr( $selected ), false );
37
	}
38
39
	/**
40
	 * @return string
41
	 */
42
	public function render(): string {
43
		return sprintf( '<option value="%s" %s>%s</option>', $this->key, $this->selected, $this->value );
44
	}
45
46
}