Completed
Push — master ( 0c53d4...debbec )
by David
09:08 queued 10s
created

Wordlift_Metabox_Field_Select   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 27.59 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A html_input() 8 22 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Metaxboxes: Integer Field.
4
 *
5
 * This file defines the Wordlift_Metabox_Field_Select class which displays select field
6
 * in WordPress' entity posts pages.
7
 *
8
 * @since   3.18.0
9
 * @package Wordlift
10
 */
11
12
/**
13
 * The Wordlift_Metabox_Field_Select class extends {@link WL_Metabox_Field} and provides
14
 * support for select fields.
15
 *
16
 * @since   3.18.0
17
 * @package Wordlift
18
 */
19
class Wordlift_Metabox_Field_Select extends WL_Metabox_Field {
20
21
	/**
22
	 * @inheritdoc
23
	 */
24
	public function html_input( $text ) {
25
		@ob_start();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
26
		?>
27
		<div class="wl-input-wrapper">
28
29
			<select name="wl_metaboxes[<?php echo $this->meta_name ?>]" id="<?php echo esc_attr( $this->meta_name ); ?>" style="width:88%;">
30 View Code Duplication
				<?php foreach ( $this->raw_custom_field['options'] as $option => $label ): ?>
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...
31
32
					<option value="<?php echo esc_attr( $option ); ?>" <?php selected( $text, $option ); ?>>
33
						<?php echo $label; ?>
34
					</option>
35
36
				<?php endforeach ?>
37
			</select>
38
39
			<div class="wl-input-notice"></div>
40
		</div>
41
		<?php
42
43
		$html = ob_get_clean();
44
		return $html;
45
	}
46
47
}
48