Completed
Pull Request — develop (#689)
by
unknown
01:46
created

TGM_Plugin_Activation   D

Complexity

Total Complexity 265

Size/Duplication

Total Lines 2091
Duplicated Lines 1.43 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 30
loc 2091
rs 4.4102
c 0
b 0
f 0
wmc 265
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
C class-tgm-plugin-activation.php ➔ tgmpa() 0 26 8

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TGM_Plugin_Activation often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TGM_Plugin_Activation, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Plugin installation and activation for WordPress themes.
4
 *
5
 * Please note that this is a drop-in library for a theme or plugin.
6
 * The authors of this library (Thomas, Gary and Juliette) are NOT responsible
7
 * for the support of your plugin or theme. Please contact the plugin
8
 * or theme author for support.
9
 *
10
 * @package   TGM-Plugin-Activation
11
 * @version   2.6.2
12
 * @link      http://tgmpluginactivation.com/
13
 * @author    Thomas Griffin, Gary Jones, Juliette Reinders Folmer
14
 * @copyright Copyright (c) 2011, Thomas Griffin
15
 * @license   GPL-2.0+
16
 */
17
18
/*
19
	Copyright 2011 Thomas Griffin (thomasgriffinmedia.com)
20
21
	This program is free software; you can redistribute it and/or modify
22
	it under the terms of the GNU General Public License, version 2, as
23
	published by the Free Software Foundation.
24
25
	This program is distributed in the hope that it will be useful,
26
	but WITHOUT ANY WARRANTY; without even the implied warranty of
27
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
	GNU General Public License for more details.
29
30
	You should have received a copy of the GNU General Public License
31
	along with this program; if not, write to the Free Software
32
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
33
*/
34
35
if ( ! defined( 'ABSPATH' ) ) {
36
	return;
37
}	
38
39
if ( ! function_exists( 'load_tgm_plugin_activation' ) ) {
40
	/**
41
	 * Ensure only one instance of the class is ever invoked.
42
	 *
43
	 * @since 2.5.0
44
	 */
45
	function load_tgm_plugin_activation() {
46
		$GLOBALS['tgmpa'] = TGM\TGM_Plugin_Activation::get_instance();
47
	}
48
}
49
50
if ( function_exists( 'did_action' ) && function_exists( 'add_action' ) ) {
51
	
52
	if ( did_action( 'plugins_loaded' ) ) {
53
		
54
		load_tgm_plugin_activation();
55
		
56
	} else {
57
		
58
		add_action( 'plugins_loaded', 'load_tgm_plugin_activation' );
59
		
60
	}
61
	
62
}
63
64
if ( ! function_exists( 'tgmpa' ) ) {
65
	/**
66
	 * Helper function to register a collection of required plugins.
67
	 *
68
	 * @since 2.0.0
69
	 * @api
70
	 *
71
	 * @param array $plugins An array of plugin arrays.
72
	 * @param array $config  Optional. An array of configuration values.
73
	 */
74
	function tgmpa( $plugins, $config = array() ) {
75
		$instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
76
77
		foreach ( $plugins as $plugin ) {
78
			call_user_func( array( $instance, 'register' ), $plugin );
79
		}
80
81
		if ( ! empty( $config ) && is_array( $config ) ) {
82
			// Send out notices for deprecated arguments passed.
83
			if ( isset( $config['notices'] ) ) {
84
				_deprecated_argument( __FUNCTION__, '2.2.0', 'The `notices` config parameter was renamed to `has_notices` in TGMPA 2.2.0. Please adjust your configuration.' );
85
				if ( ! isset( $config['has_notices'] ) ) {
86
					$config['has_notices'] = $config['notices'];
87
				}
88
			}
89
90
			if ( isset( $config['parent_menu_slug'] ) ) {
91
				_deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_menu_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' );
92
			}
93
			if ( isset( $config['parent_url_slug'] ) ) {
94
				_deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_url_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' );
95
			}
96
97
			call_user_func( array( $instance, 'config' ), $config );
98
		}
99
	}
100
}
101