Completed
Push — master ( 3b792e...5a794a )
by Stephanie
02:51
created

FrmFieldCheckbox::sanitize_value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 3
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @since 3.0
5
 */
6
class FrmFieldCheckbox extends FrmFieldType {
7
8
	/**
9
	 * @var string
10
	 * @since 3.0
11
	 */
12
	protected $type = 'checkbox';
13
14
	/**
15
	 * @var bool
16
	 * @since 3.0
17
	 */
18
	protected $holds_email_values = true;
19
20
	/**
21
	 * Does the html for this field label need to include "for"?
22
	 *
23
	 * @var bool
24
	 * @since 3.06.01
25
	 */
26
	protected $has_for_label = false;
27
28
	protected function input_html() {
29
		return $this->multiple_input_html();
30
	}
31
32
	protected function include_form_builder_file() {
33
		return $this->include_front_form_file();
34
	}
35
36
	protected function new_field_settings() {
37
		return array(
38
			'options' => serialize(
39
				array(
40
					__( 'Option 1', 'formidable' ),
41
					__( 'Option 2', 'formidable' ),
42
				)
43
			),
44
		);
45
	}
46
47
	protected function extra_field_opts() {
48
		$form_id = $this->get_field_column( 'form_id' );
49
50
		return array(
51
			'align' => FrmStylesController::get_style_val( 'check_align', ( empty( $form_id ) ? 'default' : $form_id ) ),
0 ignored issues
show
Bug introduced by
It seems like empty($form_id) ? 'default' : $form_id can also be of type array; however, FrmStylesController::get_style_val() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
52
		);
53
	}
54
55
	protected function include_front_form_file() {
56
		return FrmAppHelper::plugin_path() . '/classes/views/frm-fields/front-end/checkbox-field.php';
57
	}
58
59
	protected function show_readonly_hidden() {
60
		return true;
61
	}
62
63
	protected function prepare_import_value( $value, $atts ) {
64
		return $this->get_multi_opts_for_import( $value );
65
	}
66
}
67