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

Give_Earnings_Report   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 115
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 115
loc 115
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 14 14 2
A add_settings_page() 5 5 1
B get_settings() 34 34 1
A output() 5 5 1
A render_report_earnings_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_Earnings_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_Earnings_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_Earnings_Report.
20
	 *
21
	 * @sine 1.8
22
	 */
23
	class Give_Earnings_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    = 'earnings';
46
			$this->label = esc_html__( 'Income', '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_earnings', array( $this, 'render_report_earnings_field' ), 10, 2 );
51
52
			// Do not use main form for this tab.
53
			if( give_get_current_setting_tab() === $this->id ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
54
				add_action( 'give-reports_open_form', '__return_empty_string' );
55
				add_action( 'give-reports_close_form', '__return_empty_string' );
56
			}
57
		}
58
59
		/**
60
		 * Add this page to settings.
61
		 *
62
		 * @since  1.8
63
		 * @param  array $pages Lst of pages.
64
		 * @return array
65
		 */
66
		public function add_settings_page( $pages ) {
67
			$pages[ $this->id ] = $this->label;
68
69
			return $pages;
70
		}
71
72
		/**
73
		 * Get settings array.
74
		 *
75
		 * @since  1.8
76
		 * @return array
77
		 */
78
		public function get_settings() {
79
			// Hide save button.
80
			$GLOBALS['give_hide_save_button'] = true;
81
82
			/**
83
			 * Filter the settings.
84
			 *
85
			 * @since  1.8
86
			 * @param  array $settings
87
			 */
88
			$settings = apply_filters(
89
				'give_get_settings_' . $this->id,
90
				array(
91
					array(
92
						'id'   => 'give_tools_earnings',
93
						'type' => 'title',
94
						'table_html' => false
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
95
					),
96
					array(
97
						'id'   => 'earnings',
98
						'name' => esc_html__( 'Income', 'give' ),
99
						'type' => 'report_earnings',
100
					),
101
					array(
102
						'id'   => 'give_tools_earnings',
103
						'type' => 'sectionend',
104
						'table_html' => false
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
105
					)
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
106
				)
107
			);
108
109
			// Output.
110
			return $settings;
111
		}
112
113
		/**
114
		 * Output the settings.
115
		 *
116
		 * @since  1.8
117
		 * @return void
118
		 */
119
		public function output() {
120
			$settings = $this->get_settings();
121
122
			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
123
		}
124
125
		/**
126
		 * Render earning field
127
		 *
128
		 * @since  1.8
129
		 * @access public
130
		 *
131
		 * @param $field
132
		 * @param $option_value
133
		 */
134
		public function render_report_earnings_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...
135
			do_action( 'give_reports_view_earnings' );
136
		}
137
	}
138
139
endif;
140
141
return new Give_Earnings_Report();
142