Completed
Push — master ( a2d76a...f909ed )
by Devin
21:19 queued 03:29
created

Give::includes()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 104
Code Lines 85

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 104
ccs 0
cts 87
cp 0
rs 8.1935
cc 4
eloc 85
nc 2
nop 0
crap 20

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
1 ignored issue
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 52 and the first side effect is on line 51.

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
 * Plugin Name: Give - Donation Plugin
4
 * Plugin URI: https://givewp.com
5
 * Description: The most robust, flexible, and intuitive way to accept donations on WordPress.
6
 * Author: WordImpress
7
 * Author URI: https://wordimpress.com
8
 * Version: 1.3.6
9
 * Text Domain: give
10
 * Domain Path: /languages
11
 * GitHub Plugin URI: https://github.com/WordImpress/Give
12
 *
13
 * Give is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation, either version 2 of the License, or
16
 * any later version.
17
 *
18
 * Give is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with Give. If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 * A Tribute to Open Source:
27
 *
28
 * "Open source software is software that can be freely used, changed, and shared (in modified or unmodified form) by anyone. Open
29
 * source software is made by many people, and distributed under licenses that comply with the Open Source Definition."
30
 *
31
 * -- The Open Source Initiative
32
 *
33
 * Give is a tribute to the spirit and philosophy of Open Source. We at WordImpress gladly embrace the Open Source philosophy both
34
 * in how Give itself was developed, and how we hope to see others build more from our code base.
35
 *
36
 * Give would not have been possible without the tireless efforts of WordPress and the surrounding Open Source projects and their talented developers. Thank you all for your contribution to WordPress.
37
 *
38
 * - The WordImpress Team
39
 *
40
 */
41
42
// Exit if accessed directly
43
if ( ! defined( 'ABSPATH' ) ) {
44
	exit;
45
}
46
47
if ( ! class_exists( 'Give' ) ) : /**
48
 * Main Give Class
49
 *
50
 * @since 1.0
51
 */ {
52
	final class Give {
53
		/** Singleton *************************************************************/
54
55
56
		/**
57
		 * @var Give The one true Give
58
		 * @since 1.0
59
		 */
60
		private static $instance;
61
62
		/**
63
		 * Give Roles Object
64
		 *
65
		 * @var Give_Roles object
66
		 * @since 1.0
67
		 */
68
		public $roles;
69
70
		/**
71
		 * Give Settings Object
72
		 *
73
		 * @var Give_Plugin_Settings object
74
		 * @since 1.0
75
		 */
76
		public $give_settings;
77
78
		/**
79
		 * Give Session Object
80
		 *
81
		 * This holds donation data for user's session
82
		 *
83
		 * @var Give_Session object
84
		 * @since 1.0
85
		 */
86
		public $session;
87
88
		/**
89
		 * Give HTML Element Helper Object
90
		 *
91
		 * @var Give_HTML_Elements object
92
		 * @since 1.0
93
		 */
94
		public $html;
95
96
97
		/**
98
		 * Give Emails Object
99
		 *
100
		 * @var Give_Emails object
101
		 * @since 1.0
102
		 */
103
		public $emails;
104
105
		/**
106
		 * Give Email Template Tags Object
107
		 *
108
		 * @var Give_Email_Template_Tags object
109
		 * @since 1.0
110
		 */
111
		public $email_tags;
112
113
		/**
114
		 * Give Customers DB Object
115
		 *
116
		 * @var Give_Customer object
117
		 * @since 1.0
118
		 */
119
		public $customers;
120
121
		/**
122
		 * Give API Object
123
		 *
124
		 * @var Give_API object
125
		 * @since 1.1
126
		 */
127
		public $api;
128
129
		/**
130
		 * Give Template Loader Object
131
		 *
132
		 * @var Give_Template_Loader object
133
		 * @since 1.0
134
		 */
135
		public $template_loader;
136
137
		/**
138
		 * Main Give Instance
139
		 *
140
		 * Insures that only one instance of Give exists in memory at any one
141
		 * time. Also prevents needing to define globals all over the place.
142
		 *
143
		 * @since     1.0
144
		 * @static
145
		 * @staticvar array $instance
146
		 * @uses      Give::setup_constants() Setup the constants needed
147
		 * @uses      Give::includes() Include the required files
148
		 * @uses      Give::load_textdomain() load the language files
149
		 * @see       Give()
150
		 * @return    Give
151
		 */
152 48
		public static function instance() {
153 48
			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Give ) ) {
154
				self::$instance = new Give;
155
				self::$instance->setup_constants();
156
157
				add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
158
159
				self::$instance->includes();
160
				self::$instance->roles         = new Give_Roles();
161
				self::$instance->api           = new Give_API();
162
				self::$instance->give_settings = new Give_Plugin_Settings();
163
				self::$instance->session       = new Give_Session();
164
				self::$instance->html          = new Give_HTML_Elements();
165
				self::$instance->emails        = new Give_Emails();
166
				self::$instance->email_tags    = new Give_Email_Template_Tags();
167
				//self::$instance->donators_gravatars = new Give_Donators_Gravatars();
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
168
				self::$instance->customers       = new Give_DB_Customers();
169
				self::$instance->template_loader = new Give_Template_Loader();
170
171
			}
172
173 48
			return self::$instance;
174
		}
175
176
		/**
177
		 * Throw error on object clone
178
		 *
179
		 * The whole idea of the singleton design pattern is that there is a single
180
		 * object, therefore we don't want the object to be cloned.
181
		 *
182
		 * @since  1.0
183
		 * @access protected
184
		 * @return void
185
		 */
186
		public function __clone() {
187
			// Cloning instances of the class is forbidden
188
			_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'give' ), '1.0' );
189
		}
190
191
		/**
192
		 * Disable unserializing of the class
193
		 *
194
		 * @since  1.0
195
		 * @access protected
196
		 * @return void
197
		 */
198
		public function __wakeup() {
199
			// Unserializing instances of the class is forbidden
200
			_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'give' ), '1.0' );
201
		}
202
203
		/**
204
		 * Setup plugin constants
205
		 *
206
		 * @access private
207
		 * @since  1.0
208
		 * @return void
209
		 */
210
		private function setup_constants() {
211
212
			// Plugin version
213
			if ( ! defined( 'GIVE_VERSION' ) ) {
214
				define( 'GIVE_VERSION', '1.3.6' );
215
			}
216
217
			// Plugin Folder Path
218
			if ( ! defined( 'GIVE_PLUGIN_DIR' ) ) {
219
				define( 'GIVE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
220
			}
221
222
			// Plugin Folder URL
223
			if ( ! defined( 'GIVE_PLUGIN_URL' ) ) {
224
				define( 'GIVE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
225
			}
226
227
			// Plugin Basename aka: "give/give.php"
228
			if ( ! defined( 'GIVE_PLUGIN_BASENAME' ) ) {
229
				define( 'GIVE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
230
			}
231
232
			// Plugin Root File
233
			if ( ! defined( 'GIVE_PLUGIN_FILE' ) ) {
234
				define( 'GIVE_PLUGIN_FILE', __FILE__ );
235
			}
236
237
			// Make sure CAL_GREGORIAN is defined
238
			if ( ! defined( 'CAL_GREGORIAN' ) ) {
239
				define( 'CAL_GREGORIAN', 1 );
240
			}
241
		}
242
243
		/**
244
		 * Include required files
245
		 *
246
		 * @access private
247
		 * @since  1.0
248
		 * @return void
249
		 */
250
		private function includes() {
251
			global $give_options;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
252
253
			require_once GIVE_PLUGIN_DIR . 'includes/admin/register-settings.php';
254
			$give_options = give_get_settings();
255
256
			require_once GIVE_PLUGIN_DIR . 'includes/post-types.php';
257
			require_once GIVE_PLUGIN_DIR . 'includes/scripts.php';
258
			require_once GIVE_PLUGIN_DIR . 'includes/ajax-functions.php';
259
			require_once GIVE_PLUGIN_DIR . 'includes/actions.php';
260
			require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api.php';
261
262
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-roles.php';
263
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-template-loader.php';
264
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-donate-form.php';
265
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-db.php';
266
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-db-customers.php';
267
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-customer.php';
268
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-stats.php';
269
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-session.php';
270
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-html-elements.php';
271
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-logging.php';
272
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-license-handler.php';
273
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-cron.php';
274
275
			require_once GIVE_PLUGIN_DIR . 'includes/country-functions.php';
276
			require_once GIVE_PLUGIN_DIR . 'includes/template-functions.php';
277
			require_once GIVE_PLUGIN_DIR . 'includes/misc-functions.php';
278
			require_once GIVE_PLUGIN_DIR . 'includes/forms/functions.php';
279
			require_once GIVE_PLUGIN_DIR . 'includes/forms/template.php';
280
			require_once GIVE_PLUGIN_DIR . 'includes/forms/widget.php';
281
			require_once GIVE_PLUGIN_DIR . 'includes/shortcodes.php';
282
			require_once GIVE_PLUGIN_DIR . 'includes/formatting.php';
283
			require_once GIVE_PLUGIN_DIR . 'includes/price-functions.php';
284
			require_once GIVE_PLUGIN_DIR . 'includes/error-tracking.php';
285
			require_once GIVE_PLUGIN_DIR . 'includes/process-purchase.php';
286
			require_once GIVE_PLUGIN_DIR . 'includes/login-register.php';
287
			require_once GIVE_PLUGIN_DIR . 'includes/user-functions.php';
288
			require_once GIVE_PLUGIN_DIR . 'includes/plugin-compatibility.php';
289
290
			require_once GIVE_PLUGIN_DIR . 'includes/payments/functions.php';
291
			require_once GIVE_PLUGIN_DIR . 'includes/payments/actions.php';
292
			require_once GIVE_PLUGIN_DIR . 'includes/payments/class-payment-stats.php';
293
			require_once GIVE_PLUGIN_DIR . 'includes/payments/class-payments-query.php';
294
			require_once GIVE_PLUGIN_DIR . 'includes/payments/class-donators-gravatars.php';
295
296
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/functions.php';
297
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/actions.php';
298
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/paypal-standard.php';
299
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/offline-donations.php';
300
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/manual.php';
301
302
			require_once GIVE_PLUGIN_DIR . 'includes/emails/class-give-emails.php';
303
			require_once GIVE_PLUGIN_DIR . 'includes/emails/class-give-email-tags.php';
304
			require_once GIVE_PLUGIN_DIR . 'includes/emails/functions.php';
305
			require_once GIVE_PLUGIN_DIR . 'includes/emails/template.php';
306
			require_once GIVE_PLUGIN_DIR . 'includes/emails/actions.php';
307
308
			if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
309
310
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-footer.php';
311
				require_once GIVE_PLUGIN_DIR . 'includes/admin/welcome.php';
312
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-pages.php';
313
				require_once GIVE_PLUGIN_DIR . 'includes/admin/class-admin-notices.php';
314
				require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
315
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-actions.php';
316
				require_once GIVE_PLUGIN_DIR . 'includes/admin/system-info.php';
317
				require_once GIVE_PLUGIN_DIR . 'includes/admin/export-functions.php';
318
				require_once GIVE_PLUGIN_DIR . 'includes/admin/add-ons.php';
319
				require_once GIVE_PLUGIN_DIR . 'includes/admin/plugins.php';
320
				require_once GIVE_PLUGIN_DIR . 'includes/admin/dashboard-widgets.php';
321
322
				require_once GIVE_PLUGIN_DIR . 'includes/admin/payments/actions.php';
323
				require_once GIVE_PLUGIN_DIR . 'includes/admin/payments/payments-history.php';
324
325
				require_once GIVE_PLUGIN_DIR . 'includes/admin/customers/customers.php';
326
				require_once GIVE_PLUGIN_DIR . 'includes/admin/customers/customer-functions.php';
327
				require_once GIVE_PLUGIN_DIR . 'includes/admin/customers/customer-actions.php';
328
				require_once GIVE_PLUGIN_DIR . 'includes/admin/forms/metabox.php';
329
				require_once GIVE_PLUGIN_DIR . 'includes/admin/forms/dashboard-columns.php';
330
331
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/reports.php';
332
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/pdf-reports.php';
333
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/class-give-graph.php';
334
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/graphing.php';
335
336
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/abstract-shortcode-generator.php';
337
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/class-shortcode-button.php';
338
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-form.php';
339
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-goal.php';
340
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-login.php';
341
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-register.php';
342
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-profile-editor.php';
343
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-donation-history.php';
344
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-receipt.php';
345
346
				require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php';
347
				require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrades.php';
348
349
			}
350
351
			require_once GIVE_PLUGIN_DIR . 'includes/install.php';
352
353
		}
354
355
		/**
356
		 * Loads the plugin language files
357
		 *
358
		 * @access public
359
		 * @since  1.0
360
		 * @return void
361
		 */
362
		public function load_textdomain() {
363
			// Set filter for Give's languages directory
364
			$give_lang_dir = dirname( plugin_basename( GIVE_PLUGIN_FILE ) ) . '/languages/';
365
			$give_lang_dir = apply_filters( 'give_languages_directory', $give_lang_dir );
366
367
			// Traditional WordPress plugin locale filter
368
			$locale = apply_filters( 'plugin_locale', get_locale(), 'give' );
369
			$mofile = sprintf( '%1$s-%2$s.mo', 'give', $locale );
370
371
			// Setup paths to current locale file
372
			$mofile_local  = $give_lang_dir . $mofile;
373
			$mofile_global = WP_LANG_DIR . '/give/' . $mofile;
374
375
			if ( file_exists( $mofile_global ) ) {
376
				// Look in global /wp-content/languages/give folder
377
				load_textdomain( 'give', $mofile_global );
378
			} elseif ( file_exists( $mofile_local ) ) {
379
				// Look in local location from filter `give_languages_directory`
380
				load_textdomain( 'give', $mofile_local );
381
			} else {
382
				// Load the default language files packaged up w/ Give
383
				load_plugin_textdomain( 'give', false, $give_lang_dir );
384
			}
385
		}
386
	}
387
}
388
389
endif; // End if class_exists check
390
391
392
/**
393
 * The main function responsible for returning the one true Give
394
 * Instance to functions everywhere.
395
 *
396
 * Use this function like you would a global variable, except without needing
397
 * to declare the global.
398
 *
399
 * Example: <?php $give = Give(); ?>
400
 *
401
 * @since 1.0
402
 * @return object - The one true Give Instance
403
 */
404
function Give() {
405 48
	return Give::instance();
406
}
407
408
// Get Give Running
409
Give();
410