Text   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A render() 0 10 1
1
<?php
2
3
4
namespace lloc\Msls\Component\Input;
5
6
7
use lloc\Msls\Component\InputInterface;
8
9
class Text implements InputInterface {
10
11
	/**
12
	 * @var string
13
	 */
14
	protected $key;
15
16
	/**
17
	 * @var string
18
	 */
19
	protected $value;
20
21
	/**
22
	 * @var string
23
	 */
24
	protected $size;
25
26
	/**
27
	 * @var string
28
	 */
29
	protected $readonly;
30
31
	/**
32
	 * @param string $key
33
	 * @param string|null $value
34
	 * @param string $size
35
	 * @param bool $readonly
36
	 */
37
	public function __construct( string $key, $value, string $size = '30', bool $readonly = false ) {
38
		$this->key      = esc_attr( $key );
39
		$this->value    = esc_attr( $value );
40
		$this->size     = esc_attr( $size );
41
		$this->readonly = $readonly ? ' readonly="readonly"' : '';
42
	}
43
44
	/**
45
	 * @return string
46
	 */
47
	public function render(): string {
48
		return sprintf(
49
			'<input type="text" class="regular-text" id="%1$s" name="msls[%1$s]" value="%2$s" size="%3$s"%4$s/>',
50
			$this->key,
51
			$this->value,
52
			$this->size,
53
			$this->readonly
54
		);
55
56
	}
57
58
}