Completed
Push — master ( 79386d...2cfa6f )
by Zack
18:13 queued 12:52
created

GravityView_Field_UID::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 1
b 0
f 1
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 9 and the first side effect is on line 63.

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-uid.php
4
 * @since 1.17.4
5
 * @package GravityView
6
 * @subpackage includes\fields
7
 */
8
9
class GravityView_Field_UID extends GravityView_Field {
10
11
	var $name = 'uid';
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...
12
13
	var $group = 'advanced';
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...
14
15
	public function __construct() {
16
		$this->label = esc_html__( 'Unique ID', 'gravityview' );
17
		$this->default_search_label = $this->label;
18
19
		$this->edit_entry_add_hooks();
20
21
		parent::__construct();
22
	}
23
24
	/**
25
	 * Add Edit Entry hooks
26
	 *
27
	 * @since 1.17.4
28
	 *
29
	 * @return void
30
	 */
31
	private function edit_entry_add_hooks() {
32
		add_filter( 'gravityview/edit_entry/form_fields', array( $this, 'edit_entry_fix_hidden_fields' ) );
33
	}
34
35
	/**
36
	 * Convert Unique ID fields to be Text fields in Edit Entry
37
	 *
38
	 * @since 1.17.4
39
	 *
40
	 * @param GF_Field[] $fields Array of fields to be shown on the Edit Entry screen
41
	 *
42
	 * @return GF_Field[] Array of fields, with any hidden fields replaced with text fields
43
	 */
44
	function edit_entry_fix_hidden_fields( $fields ) {
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...
45
46
		/** @var GF_Field $field */
47
		foreach( $fields as &$field ) {
48
			if ( 'uid' === $field->type ) {
49
50
				// Replace GF_Field with GF_Field_Text, copying all the data from $field
51
				$field = new GF_Field_Text( $field );
52
53
				// Everything is copied from $field, so we need to manually set the type
54
				$field->type = 'text';
55
			}
56
		}
57
58
		return $fields;
59
	}
60
61
}
62
63
new GravityView_Field_UID;
64