Radio::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 4
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Radio Field
4
 *
5
 * @package SimpleCalendar/Admin
6
 */
7
namespace SimpleCalendar\Admin\Fields;
8
9
use SimpleCalendar\Abstracts\Field;
10
11
if ( ! defined( 'ABSPATH' ) ) {
12
	exit;
13
}
14
15
/**
16
 * Radio input field.
17
 *
18
 * Outputs a fieldset of radio inputs for multiple choices.
19
 *
20
 * @since 3.0.0
21
 */
22
class Radio extends Field {
23
24
	/**
25
	 * Inline radios.
26
	 *
27
	 * @access private
28
	 * @var bool
29
	 */
30
	private $inline = false;
31
32
	/**
33
	 * Construct.
34
	 *
35
	 * @since 3.0.0
36
	 *
37
	 * @param array $field
38
	 */
39
	public function __construct( $field ) {
40
41
		$this->type_class = 'simcal-field-radios';
42
		$this->inline     = isset( $field['inline'] ) ? ( 'inline' == $field['inline'] ? true : false ) : false;
43
44
		parent::__construct( $field );
45
	}
46
47
	/**
48
	 * Outputs the field markup.
49
	 *
50
	 * @since 3.0.0
51
	 */
52
	public function html() {
53
54
		?>
55
		<fieldset id="<?php echo $this->id; ?>"
56
		          class="<?php echo $this->class; ?>"
57
			<?php echo $this->style ? 'style="' . $this->style .'"' : ''; ?>>
58
			<?php
59
60
			echo $this->description ? '<p class="description">' . wp_kses_post( $this->description ) . '</p>' : '';
61
62
			if ( ! empty( $this->title ) ) :
63
64
				?>
65
				<legend class="screen-reader-text">
66
					<span><?php echo $this->title; ?></span>
67
				</legend>
68
				<?php
69
70
			endif;
71
72
			?>
73
			<ul <?php echo $this->inline === true ? 'class="simcal-field-radios-inline"' : ''; ?>>
74 View Code Duplication
				<?php foreach ( $this->options as $option => $name ) : ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
					<li>
76
						<label for="<?php echo $this->id . '-' . trim( strval( $option ) ); ?>">
77
							<input name="<?php echo $this->name; ?>"
78
							       id="<?php echo $this->id . '-' . trim( strval( $option ) ); ?>"
79
							       class="simcal-field simcal-field-radio"
80
							       type="radio"
81
							       value="<?php echo trim( strval( $option ) ); ?>"
82
								<?php echo $this->attributes; ?>
83
								<?php checked( $option, $this->value, true ); ?>
84
								/>
85
							<?php echo esc_attr( $name ); ?>
86
						</label>
87
					</li>
88
				<?php endforeach; ?>
89
			</ul>
90
91
			<?php echo $this->tooltip; ?>
92
93
		</fieldset>
94
		<?php
95
96
	}
97
98
}
99