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

Option   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 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 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
}