Completed
Push — develop ( 454e93...224a97 )
by Zack
04:28
created

GravityView_Plugin_Hooks_Gravity_Perks   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add_hooks() 0 7 1
A edit_entry_fix_uid_fields() 0 16 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 19 and the first side effect is on line 69.

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
 * Fix Gravity Perks conflicts with GravityView
4
 *
5
 * @file      class-gravityview-plugin-hooks-gravity-perks.php
6
 * @package   GravityView
7
 * @license   GPL2+
8
 * @author    Katz Web Services, Inc.
9
 * @link      https://gravityview.co
10
 * @copyright Copyright 2016, Katz Web Services, Inc.
11
 *
12
 * @since 1.17.5
13
 */
14
15
/**
16
 * @inheritDoc
17
 * @since 1.17.5
18
 */
19
class GravityView_Plugin_Hooks_Gravity_Perks extends GravityView_Plugin_and_Theme_Hooks {
20
21
	/**
22
	 * @var string Check for the Gravity Perks class
23
	 */
24
	protected $class_name = 'GravityPerks';
25
26
27
	/**
28
	 * Filter the values shown in GravityView frontend
29
	 *
30
	 * @since 1.17
31
	 */
32
	function add_hooks() {
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...
33
34
		parent::add_hooks();
35
36
		add_filter( 'gravityview/edit_entry/form_fields', array( $this, 'edit_entry_fix_uid_fields' ) );
37
38
	}
39
40
41
	/**
42
	 * Convert Unique ID fields to be Text fields in Edit Entry
43
	 *
44
	 * @since 1.17.4
45
	 *
46
	 * @param GF_Field[] $fields Array of fields to be shown on the Edit Entry screen
47
	 *
48
	 * @return GF_Field[] Array of fields, with any hidden fields replaced with text fields
49
	 */
50
	function edit_entry_fix_uid_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...
51
52
		/** @var GF_Field $field */
53
		foreach( $fields as &$field ) {
54
			if ( 'uid' === $field->type ) {
55
56
				// Replace GF_Field with GF_Field_Text, copying all the data from $field
57
				$field = new GF_Field_Text( $field );
58
59
				// Everything is copied from $field, so we need to manually set the type
60
				$field->type = 'text';
61
			}
62
		}
63
64
		return $fields;
65
	}
66
67
}
68
69
new GravityView_Plugin_Hooks_Gravity_Perks;