Conditions | 12 |
Paths | 64 |
Total Lines | 76 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
9 | function gc_communities_init() |
||
10 | { |
||
11 | $subtypes = elgg_get_plugin_setting('subtypes', 'gc_communities'); |
||
12 | if (!$subtypes) { |
||
13 | elgg_set_plugin_setting('subtypes', json_encode(array('blog', 'groupforumtopic', 'event_calendar', 'file', 'bookmarks')), 'gc_communities'); |
||
14 | } |
||
15 | |||
16 | // Register ajax save action |
||
17 | elgg_register_action("gc_communities/save", __DIR__ . "/actions/gc_communities/save.php"); |
||
18 | |||
19 | // Register ajax tag view |
||
20 | elgg_register_ajax_view("tags/form"); |
||
21 | |||
22 | // Register streaming ajax calls |
||
23 | elgg_register_ajax_view('ajax/community_feed'); |
||
24 | |||
25 | $communities = json_decode(elgg_get_plugin_setting('communities', 'gc_communities'), true); |
||
26 | $context = array(); |
||
27 | |||
28 | if (count($communities) > 0) { |
||
29 | $parent = new ElggMenuItem('communities', elgg_echo('gc_communities:communities') . '<span class="expicon glyphicon glyphicon-chevron-down"></span>', '#communities_menu'); |
||
30 | elgg_register_menu_item('site', $parent); |
||
31 | |||
32 | foreach ($communities as $community) { |
||
33 | $url = $community['community_url']; |
||
34 | $community_animator = $community['community_animator']; |
||
35 | |||
36 | $text = (get_current_language() == 'fr') ? $community['community_fr'] : $community['community_en']; |
||
37 | if (elgg_is_logged_in() && (elgg_is_admin_logged_in() || $community_animator == elgg_get_logged_in_user_entity()->username)) { |
||
38 | $text .= " <span class='elgg-lightbox' data-colorbox-opts='".json_encode(['href'=>elgg_normalize_url('ajax/view/tags/form?community_url='.$url),'width'=>'800px','height'=>'255px'])."'><span class='fa fa-cog fa-lg'><span class='wb-inv'>Customize this Community</span></span></span>"; |
||
39 | } |
||
40 | |||
41 | //Register Community page handler |
||
42 | elgg_register_page_handler($url, 'gc_community_page_handler'); |
||
43 | |||
44 | //Register each Community page menu link |
||
45 | elgg_register_menu_item('communities', array( |
||
46 | 'name' => $url, |
||
47 | 'href' => elgg_get_site_url() . $url, |
||
48 | 'text' => $text |
||
49 | )); |
||
50 | |||
51 | $parent->addChild(elgg_get_menu_item('communities', $url)); |
||
|
|||
52 | $parent->setLinkClass('item'); |
||
53 | |||
54 | $context[] = "gc_communities-" . $url; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | // Register plugin hooks |
||
59 | elgg_register_plugin_hook_handler('permissions_check', 'object', 'gc_communities_permissions_hook'); |
||
60 | elgg_register_plugin_hook_handler('permissions_check', 'widget_layout', 'gc_communities_widget_permissions_hook'); |
||
61 | |||
62 | // Register widgets for custom Community pages |
||
63 | elgg_register_widget_type('filtered_activity_index', elgg_echo('gc_communities:filtered_activity_index'), elgg_echo('gc_communities:filtered_activity_index'), $context, true); |
||
64 | |||
65 | if (elgg_is_active_plugin('blog')) { |
||
66 | elgg_register_widget_type('filtered_blogs_index', elgg_echo('gc_communities:filtered_blogs_index'), elgg_echo('gc_communities:filtered_blogs_index'), $context, true); |
||
67 | } |
||
68 | |||
69 | elgg_register_widget_type('filtered_discussions_index', elgg_echo('gc_communities:filtered_discussions_index'), elgg_echo('gc_communities:filtered_discussions_index'), $context, true); |
||
70 | |||
71 | if (elgg_is_active_plugin('event_calendar')) { |
||
72 | elgg_register_widget_type('filtered_events_index', elgg_echo('gc_communities:filtered_events_index'), elgg_echo('gc_communities:filtered_events_index'), $context, true); |
||
73 | } |
||
74 | |||
75 | if (elgg_is_active_plugin('groups')) { |
||
76 | elgg_register_widget_type('filtered_groups_index', elgg_echo('gc_communities:filtered_groups_index'), elgg_echo('gc_communities:filtered_groups_index'), $context, true); |
||
77 | } |
||
78 | |||
79 | // Only for GCcollab |
||
80 | $site = elgg_get_site_entity(); |
||
81 | if (strpos(strtolower($site->name), 'gccollab') !== false) { |
||
82 | elgg_register_widget_type('filtered_members_index', elgg_echo('gc_communities:filtered_members_index'), elgg_echo('gc_communities:filtered_members_index'), $context, true); |
||
83 | } |
||
84 | } |
||
85 | |||
295 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: