Completed
Pull Request — master (#54)
by Jamie
03:26
created

FrmFieldOption::set_option_label()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @since 2.03.05
5
 */
6
class FrmFieldOption {
7
8
	/**
9
	 * @var string|int
10
	 *
11
	 * @since 2.03.05
12
	 */
13
	protected $option_key;
14
15
	/**
16
	 * @var string|array
17
	 *
18
	 * @since 2.03.05
19
	 */
20
	protected $option;
21
22
	/**
23
	 * @var string
24
	 * @since 2.03.05
25
	 */
26
	protected $saved_value = '';
27
28
	/**
29
	 * @var string
30
	 * @since 2.03.05
31
	 */
32
	protected $option_label = '';
33
34
	public function __construct( $option_key, $option, $args = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
		$this->option_key = $option_key;
36
		$this->option = $option;
37
		$this->set_option_label();
38
		$this->set_saved_value();
39
	}
40
41
	/**
42
	 * Set the option label
43
	 *
44
	 * @since 2.03.05
45
	 */
46
	private function set_option_label() {
47
		if ( is_array( $this->option ) ) {
48
			$this->option_label = ( isset( $this->option['label'] ) ? $this->option['label'] : reset( $this->option ) );
49
		} else {
50
			$this->option_label = $this->option;
51
		}
52
	}
53
54
	/**
55
	 * Set the saved value
56
	 *
57
	 * @since 2.03.05
58
	 */
59
	protected function set_saved_value() {
60
		$this->saved_value = $this->option_label;
61
	}
62
63
	/**
64
	 * Print a single option
65
	 *
66
	 * @since 2.03.05
67
	 *
68
	 * @param string $selected_value
69
	 * @param int $truncate
70
	 */
71
	public function print_single_option( $selected_value, $truncate ) {
72
		echo '<option value="' . esc_attr( $this->saved_value ) . '"';
73
		selected( esc_attr( $selected_value ), esc_attr( $this->saved_value ) );
74
		// TODO: add hook that can add attributes to option text
75
		echo '>';
76
		echo FrmAppHelper::truncate( $this->option_label, $truncate ) . '</option>';
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'FrmAppHelper'
Loading history...
77
	}
78
79
}