Completed
Push — master ( 3c32f9...42fff5 )
by Paweł
03:24
created

CodeFixer::getBasicFunctionRenames()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 86
Code Lines 77

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 79
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 77
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 86
ccs 79
cts 79
cp 1
crap 4
rs 8.4338

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
2
namespace CodeReview;
3
4
class CodeFixer {
5
6
	/**
7
	 * Just basic function renames from A to B
8
	 *
9
	 * @param string $maxVersion Maximum Elgg version to support
10
	 * @return array
11
	 */
12 1
	public function getBasicFunctionRenames($maxVersion = '') {
13
		$data = array(
14
			'1.7' => array(
15 1
				'elgg_validate_action_url' => 'elgg_add_action_tokens_to_url',
16 1
				'menu_item' => 'make_register_object',
17 1
				'extend_view' => 'elgg_extend_view',
18 1
				'get_views' => 'elgg_get_views',
19 1
			),
20
			'1.8' => array(
21 1
				'register_elgg_event_handler' => 'elgg_register_event_handler',
22 1
				'unregister_elgg_event_handler' => 'elgg_unregister_event_handler',
23 1
				'trigger_elgg_event' => 'elgg_trigger_event',
24 1
				'register_plugin_hook' => 'elgg_register_plugin_hook_handler',
25 1
				'unregister_plugin_hook' => 'elgg_unregister_plugin_hook_handler',
26 1
				'trigger_plugin_hook' => 'elgg_trigger_plugin_hook',
27 1
				'friendly_title' => 'elgg_get_friendly_title',
28 1
				'friendly_time' => 'elgg_view_friendly_time',
29 1
				'page_owner' => 'elgg_get_page_owner_guid',
30 1
				'page_owner_entity' => 'elgg_get_page_owner_entity',
31 1
				'set_page_owner' => 'elgg_set_page_owner_guid',
32 1
				'set_context' => 'elgg_set_context',
33 1
				'get_context' => 'elgg_get_context',
34 1
				'get_plugin_name' => 'elgg_get_calling_plugin_id',
35 1
				'is_plugin_enabled' => 'elgg_is_active_plugin',
36 1
				'set_user_validation_status' => 'elgg_set_user_validation_status',
37 1
				'get_loggedin_user' => 'elgg_get_logged_in_user_entity',
38 1
				'get_loggedin_userid' => 'elgg_get_logged_in_user_guid',
39 1
				'isloggedin' => 'elgg_is_logged_in',
40 1
				'isadminloggedin' => 'elgg_is_admin_logged_in',
41 1
				'load_plugins' => '_elgg_load_plugins',
42 1
				'set_plugin_usersetting' => 'elgg_set_plugin_user_setting',
43 1
				'clear_plugin_usersetting' => 'elgg_unset_plugin_user_setting',
44 1
				'get_plugin_usersetting' => 'elgg_get_plugin_user_setting',
45 1
				'set_plugin_setting' => 'elgg_set_plugin_setting',
46 1
				'get_plugin_setting' => 'elgg_get_plugin_setting',
47 1
				'clear_plugin_setting' => 'elgg_unset_plugin_setting',
48 1
				'clear_all_plugin_settings' => 'elgg_unset_all_plugin_settings',
49 1
				'set_view_location' => 'elgg_set_view_location',
50 1
				'get_metadata' => 'elgg_get_metadata_from_id',
51 1
				'get_annotation' => 'elgg_get_annotation_from_id',
52 1
				'register_page_handler' => 'elgg_register_page_handler',
53 1
				'unregister_page_handler' => 'elgg_unregister_page_handler',
54 1
				'register_entity_type' => 'elgg_register_entity_type',
55 1
				'elgg_view_register_simplecache' => 'elgg_register_simplecache_view',
56 1
				'elgg_view_regenerate_simplecache' => 'elgg_regenerate_simplecache',
57 1
				'elgg_view_enable_simplecache' => 'elgg_enable_simplecache',
58 1
				'elgg_view_disable_simplecache' => 'elgg_disable_simplecache',
59 1
				'remove_widget_type' => 'elgg_unregister_widget_type',
60 1
				'widget_type_exists' => 'elgg_is_widget_type',
61 1
				'get_widget_types' => 'elgg_get_widget_types',
62 1
				'display_widget' => 'elgg_view_entity',
63 1
				'invalidate_cache_for_entity' => '_elgg_invalidate_cache_for_entity',
64 1
				'cache_entity' => '_elgg_cache_entity',
65 1
				'retrieve_cached_entity' => '_elgg_retrieve_cached_entity',
66 1
			),
67
			'1.9' => array(
68 1
				'setup_db_connections' => '_elgg_services()->db->setupConnections',
69 1
				'get_db_link' => '_elgg_services()->db->getLink',
70 1
				'get_db_error' => 'mysql_error',
71 1
				'execute_delayed_query' => '_elgg_services()->db->registerDelayedQuery',
72 1
				'elgg_regenerate_simplecache' => 'elgg_invalidate_simplecache',
73 1
				'elgg_get_filepath_cache' => 'elgg_get_system_cache',
74 1
				'elgg_filepath_cache_reset' => 'elgg_reset_system_cache',
75 1
				'elgg_filepath_cache_save' => 'elgg_save_system_cache',
76 1
				'elgg_filepath_cache_load' => 'elgg_load_system_cache',
77 1
				'elgg_enable_filepath_cache' => 'elgg_enable_system_cache',
78 1
				'elgg_disable_filepath_cache' => 'elgg_disable_system_cache',
79 1
				'unregister_entity_type' => 'elgg_unregister_entity_type',
80 1
				'autop' => 'elgg_autop',
81 1
				'xml_to_object' => 'new ElggXMLElement',
82 1
				'unregister_notification_handler' => 'elgg_unregister_notification_method',
83 1
			),
84
			'1.10' => array(
85 1
				'file_get_general_file_type' => 'elgg_get_file_simple_type',
86 1
				'file_get_simple_type' => 'elgg_get_file_simple_type',
87 1
			),
88 1
		);
89
90 1
		$result = array();
91 1
		foreach ($data as $version => $rows) {
92 1
			if (!$maxVersion || version_compare($version, $maxVersion, '<=')) {
93 1
				$result = array_merge($result, $rows);
94 1
			}
95 1
		}
96 1
		return $result;
97
	}
98
99
	/**
100
	 * Function renames from A to B with parameters manipulation
101
	 *
102
	 * @return array
103
	 */
104
	public function getBasicFunctionSnippets() {
105
		return array(
106
			'elgg_get_entity_owner_where_sql' => '_elgg_get_guid_based_where_sql',
107
			'elgg_get_entity_container_where_sql' => '_elgg_get_guid_based_where_sql',
108
			'elgg_get_entity_site_where_sql' => '_elgg_get_guid_based_where_sql',
109
110
//			'get_entities_from_access_id' => 'elgg_get_entities_from_access_id', //bad params count
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
111
//			'get_entities_from_annotations' => 'elgg_get_entities_from_annotations',//bad params count
112
//			'list_entities_from_annotations' => 'elgg_list_entities_from_annotations',//bad params count
113
//			'get_library_files' => 'elgg_get_file_list',//bad params count
114
//			'get_entities' => 'elgg_get_entities',//bad params count
115
//			'list_registered_entities' => 'elgg_list_registered_entities',//bad params count
116
//			'list_entities' => 'elgg_list_entities',//bad params count
117
//			'get_entities_from_metadata' => 'elgg_get_entities_from_metadata',//bad params count
118
//			'get_entities_from_metadata_multi' => 'elgg_get_entities_from_metadata',//bad params count
119
//			'get_entities_from_relationship' => 'elgg_get_entities_from_relationship',//bad params count
120
//			'make_register_object' => 'add_submenu_item',//bad params count
121
//			'list_entities_from_access_id' => 'elgg_list_entities_from_access_id',//bad params count
122
//			'register_action' => 'elgg_register_action',//bad params count
123
//			'get_entities_from_annotations_calculate_x' => 'elgg_get_entities_from_annotation_calculation',//bad params count
124
//			'get_entities_from_annotation_count' => 'elgg_get_entities_from_annotation_calculation',//bad params count
125
//			'list_entities_from_annotation_count' => 'elgg_list_entities_from_annotation_calculation',//bad params count
126
//			'get_objects_in_group' => 'elgg_get_entities',//bad params count
127
//			'list_entities_groups' => 'elgg_list_entities',//bad params count
128
//			'get_entities_from_metadata_groups' => 'elgg_get_entities_from_metadata',//bad params count
129
//			'get_entities_from_metadata_groups_multi' => 'elgg_get_entities_from_metadata',//bad params count
130
//			'list_entities_in_area' => 'elgg_get_entities_from_location',//bad params count
131
//			'list_entities_location' => 'elgg_list_entities_from_location',//bad params count
132
//			'get_entities_in_area' => 'elgg_get_entities_from_location',//bad params count
133
//			'list_entities_from_metadata' => 'elgg_list_entities_from_metadata',//bad params count
134
//			'list_entities_from_metadata_multi' => 'elgg_list_entities_from_metadata',//bad params count
135
//			'regenerate_plugin_list' => '_elgg_generate_plugin_entities',//bad params count
136
		);
137
	}
138
139
	/**
140
	 * @return array of
141
	 */
142
	public function getRegExpPairs() {
143
		return array(
144
			'([^_a-zA-Z0-9])register_plugin_hook([^_a-zA-Z0-9])' => '$1elgg_register_plugin_hook_handler$2',
145
		);
146
	}
147
148
	/**
149
	 * We'll need
150
	 * - function renames
151
	 * - function renames with parameter modifications
152
	 * - function replacements with complex snippets
153
	 */
154
}