Completed
Pull Request — gcconnex (#1540)
by Nick
16:17
created

start.php ➔ apiadmin_get_usage_log()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 86
Code Lines 22

Duplication

Lines 8
Ratio 9.3 %

Importance

Changes 0
Metric Value
cc 6
eloc 22
nc 24
nop 11
dl 8
loc 86
rs 8.3234
c 0
b 0
f 0

How to fix   Long Method    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Elgg API Admin
4
 * Upgraded to Elgg 1.8 (tested on 1.8.8) and added rename and regenerate actions
5
 * 
6
 * @package ElggAPIAdmin
7
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
8
 * 
9
 * @author Curverider Ltd
10
 * @copyright Curverider Ltd 2011
11
 * @link http://www.elgg.org
12
*/
13
14
elgg_register_event_handler('init','system','apiadmin_init');
15
16
/**
17
 * Initialise the API Admin tool on init,system
18
 *
19
 * @param unknown_type $event
20
 * @param unknown_type $object_type
21
 * @param unknown_type $object
22
*/
23
function apiadmin_init($event, $object_type, $object = null) {
24
	// Add a page to the admin area
25
	elgg_register_admin_menu_item('administer', 'apiadmin', 'administer_utilities');
26
27
	// Hook into delete to revoke secret keys
28
	elgg_register_event_handler('delete', 'object', 'apiadmin_delete_key');
29
30
	// Register some actions
31
	$plugindir = dirname(__FILE__);
32
	elgg_register_action('apiadmin/revokekey', $plugindir . '/actions/apiadmin/revokekey.php', 'admin');
33
	elgg_register_action('apiadmin/generate', $plugindir . '/actions/apiadmin/generate.php', 'admin');
34
	elgg_register_action('apiadmin/renamekey', $plugindir . '/actions/apiadmin/renamekey.php', 'admin');
35
	elgg_register_action('apiadmin/regenerate', $plugindir . '/actions/apiadmin/regenerate.php', 'admin');
36
}
37
38
/**
39
 * Event handler for when an API key is deleted
40
 * 
41
 * @param unknown_type $event
42
 * @param unknown_type $object_type
43
 * @param unknown_type $object
44
 */
45
function apiadmin_delete_key($event, $object_type, $object = null) {
46
	global $CONFIG;
47
48
	if ( ($object) && ($object->subtype === get_subtype_id('object', 'api_key')) ) {
49
		// Delete secret key
50
		return remove_api_user($CONFIG->site_id, $object->public);
51
	}
52
53
	return true;
54
}
55