Test Failed
Branch master (049c7e)
by Devin
12:45 queued 07:50
created

Give_Donors_Report   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 110
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 110
loc 110
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A add_settings_page() 5 5 1
B get_settings() 34 34 1
A output() 5 5 1
A render_report_donors_field() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Give Reports Page/Tab
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_Donors_Report
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
 * @since       1.8
10
 */
11
12
if ( ! defined( 'ABSPATH' ) ) {
13
	exit; // Exit if accessed directly
14
}
15
16 View Code Duplication
if ( ! class_exists( 'Give_Donors_Report' ) ) :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
18
	/**
19
	 * Give_Donors_Report.
20
	 *
21
	 * @sine 1.8
22
	 */
23
	class Give_Donors_Report {
24
25
		/**
26
		 * Setting page id.
27
		 *
28
		 * @since 1.8
29
		 * @var   string
30
		 */
31
		protected $id = '';
32
33
		/**
34
		 * Setting page label.
35
		 *
36
		 * @since 1.8
37
		 * @var   string
38
		 */
39
		protected $label = '';
40
41
		/**
42
		 * Constructor.
43
		 */
44
		public function __construct() {
45
			$this->id    = 'donors';
46
			$this->label = esc_html__( 'Donors', 'give' );
47
48
			add_filter( 'give-reports_tabs_array', array( $this, 'add_settings_page' ), 20 );
49
			add_action( "give-reports_settings_{$this->id}_page", array( $this, 'output' ) );
50
			add_action( 'give_admin_field_report_donors', array( $this, 'render_report_donors_field' ), 10, 2 );
51
52
		}
53
54
		/**
55
		 * Add this page to settings.
56
		 *
57
		 * @since  1.8
58
		 * @param  array $pages List of pages.
59
		 * @return array
60
		 */
61
		public function add_settings_page( $pages ) {
62
			$pages[ $this->id ] = $this->label;
63
64
			return $pages;
65
		}
66
67
		/**
68
		 * Get settings array.
69
		 *
70
		 * @since  1.8
71
		 * @return array
72
		 */
73
		public function get_settings() {
74
			// Hide save button.
75
			$GLOBALS['give_hide_save_button'] = true;
76
77
			/**
78
			 * Filter the settings.
79
			 *
80
			 * @since  1.8
81
			 * @param  array $settings
82
			 */
83
			$settings = apply_filters(
84
				'give_get_settings_' . $this->id,
85
				array(
86
					array(
87
						'id'   => 'give_reports_donors',
88
						'type' => 'title',
89
						'table_html' => false
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
90
					),
91
					array(
92
						'id'   => 'donors',
93
						'name' => esc_html__( 'Donors', 'give' ),
94
						'type' => 'report_donors',
95
					),
96
					array(
97
						'id'   => 'give_reports_donors',
98
						'type' => 'sectionend',
99
						'table_html' => false
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
100
					)
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
101
				)
102
			);
103
104
			// Output.
105
			return $settings;
106
		}
107
108
		/**
109
		 * Output the settings.
110
		 *
111
		 * @since  1.8
112
		 * @return void
113
		 */
114
		public function output() {
115
			$settings = $this->get_settings();
116
117
			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
118
		}
119
120
		/**
121
		 * Render report donors field
122
		 *
123
		 * @since  1.8
124
		 * @access public
125
		 *
126
		 * @param $field
127
		 * @param $option_value
128
		 */
129
		public function render_report_donors_field( $field, $option_value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $option_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
130
			do_action( 'give_reports_view_donors');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
131
		}
132
	}
133
134
endif;
135
136
return new Give_Donors_Report();
137