Completed
Push — develop ( 7b8d22...20c6d6 )
by Zack
05:12
created

GravityView_Field_Checkbox   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 55
rs 10
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B field_options() 0 26 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 64.

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 $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...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
13
14
	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...
15
16
	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...
17
18
	public function __construct() {
19
		$this->label = esc_html__( 'Checkbox', 'gravityview' );
20
		parent::__construct();
21
	}
22
23
	/**
24
	 * Add `choice_display` setting to the field
25
	 * 
26
	 * @param array $field_options
27
	 * @param string $template_id
28
	 * @param string $field_id
29
	 * @param string $context
30
	 * @param string $input_type
31
	 *
32
	 * @since 1.17
33
	 *
34
	 * @return array
35
	 */
36
	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...
37
38
		// Set the $_field_id var
39
		$field_options = parent::field_options( $field_options, $template_id, $field_id, $context, $input_type );
40
41
		// It's not the parent field; it's an input
42
		if( floor( $field_id ) !== floatval( $field_id ) ) {
43
44
			if( $this->is_choice_value_enabled() ) {
45
				$field_options['choice_display'] = array(
46
					'type'    => 'radio',
47
					'value'   => 'value',
48
					'class'   => 'vertical',
49
					'label'   => __( 'What should be displayed:', 'gravityview' ),
50
					'desc'    => __( 'This input has a label and a value. What should be displayed?', 'gravityview' ),
51
					'choices' => array(
52
						'tick' => __( 'A check mark, if the input is checked', 'gravityview' ),
53
						'value' => __( 'Value of the input', 'gravityview' ),
54
						'label' => __( 'Label of the input', 'gravityview' ),
55
					),
56
				);
57
			}
58
		}
59
60
		return $field_options;
61
	}
62
}
63
64
new GravityView_Field_Checkbox;
65