Completed
Push — develop ( 7592b8...3eb7c5 )
by Zack
14:44
created

GravityView_Field_Checkbox   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 73
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B field_options() 0 38 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 82.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @file class-gravityview-field-checkbox.php
4
 * @package GravityView
5
 * @subpackage includes\fields
6
 */
7
8
class GravityView_Field_Checkbox extends GravityView_Field {
9
10
	var $name = 'checkbox';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
12
	var $is_searchable = true;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $is_searchable.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
14
	/**
15
	 * @see GFCommon::get_field_filter_settings Gravity Forms suggests checkboxes should just be "is"
16
	 * @var array
17
	 */
18
	var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains' );
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $search_operators.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
19
20
	var $_gf_field_class_name = 'GF_Field_Checkbox';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $_gf_field_class_name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
21
22
	var $group = 'standard';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $group.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
23
24
	public function __construct() {
25
		$this->label = esc_html__( 'Checkbox', 'gravityview' );
26
		parent::__construct();
27
	}
28
29
	/**
30
	 * Add `choice_display` setting to the field
31
	 * 
32
	 * @param array $field_options
33
	 * @param string $template_id
34
	 * @param string $field_id
35
	 * @param string $context
36
	 * @param string $input_type
37
	 *
38
	 * @since 1.17
39
	 *
40
	 * @return array
41
	 */
42
	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
43
44
		// Set the $_field_id var
45
		$field_options = parent::field_options( $field_options, $template_id, $field_id, $context, $input_type );
46
47
		// It's not the parent field; it's an input
48
		if( floor( $field_id ) !== floatval( $field_id ) ) {
49
50
			if( $this->is_choice_value_enabled() ) {
51
52
				$desc = esc_html__( 'This input has a label and a value. What should be displayed?', 'gravityview' );
53
				$default = 'value';
54
				$choices = array(
55
					'tick' => __( 'A check mark, if the input is checked', 'gravityview' ),
56
					'value' => __( 'Value of the input', 'gravityview' ),
57
					'label' => __( 'Label of the input', 'gravityview' ),
58
				);
59
			} else {
60
				$desc = '';
61
				$default = 'tick';
62
				$choices = array(
63
					'tick' => __( 'A check mark, if the input is checked', 'gravityview' ),
64
					'label' => __( 'Label of the input', 'gravityview' ),
65
				);
66
			}
67
68
			$field_options['choice_display'] = array(
69
				'type'    => 'radio',
70
				'class'   => 'vertical',
71
				'label'   => __( 'What should be displayed:', 'gravityview' ),
72
				'value'   => $default,
73
				'desc'    => $desc,
74
				'choices' => $choices,
75
			);
76
		}
77
78
		return $field_options;
79
	}
80
}
81
82
new GravityView_Field_Checkbox;
83