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

Text::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
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
	 * @return string
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
38
	 */
39
	public function __construct( string $key, $value, string $size = '30', bool $readonly = false ) {
40
		$this->key      = esc_attr( $key );
41
		$this->value    = esc_attr( $value );
42
		$this->size     = esc_attr( $size );
43
		$this->readonly = $readonly ? ' readonly="readonly"' : '';
44
	}
45
46
	/**
47
	 * @return string
48
	 */
49
	public function render(): string {
50
		return sprintf(
51
			'<input type="text" class="regular-text" id="%1$s" name="msls[%1$s]" value="%2$s" size="%3$s"%4$s/>',
52
			$this->key,
53
			$this->value,
54
			$this->size,
55
			$this->readonly
56
		);
57
58
	}
59
60
}