| Conditions | 4 |
| Paths | 3 |
| Total Lines | 110 |
| Code Lines | 69 |
| 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 |
||
| 13 | function pleio_init() { |
||
| 14 | elgg_unregister_page_handler("login"); |
||
| 15 | elgg_register_page_handler("login", "pleio_page_handler"); |
||
| 16 | |||
| 17 | elgg_unregister_action("register"); |
||
| 18 | elgg_unregister_page_handler("register"); |
||
| 19 | |||
| 20 | elgg_unregister_action("logout"); |
||
| 21 | elgg_register_action("logout", dirname(__FILE__) . "/actions/logout.php", "public"); |
||
| 22 | |||
| 23 | elgg_unregister_action("user/passwordreset"); |
||
| 24 | elgg_unregister_action("user/requestnewpassword"); |
||
| 25 | |||
| 26 | elgg_unregister_action("admin/user/resetpassword"); |
||
| 27 | |||
| 28 | elgg_unregister_menu_item("page", "users:add"); |
||
| 29 | elgg_unregister_action("useradd"); |
||
| 30 | |||
| 31 | elgg_register_plugin_hook_handler("register", "menu:user_hover", "pleio_user_hover_menu"); |
||
| 32 | |||
| 33 | elgg_unregister_plugin_hook_handler("usersettings:save", "user", "users_settings_save"); |
||
| 34 | |||
| 35 | elgg_unregister_action("admin/site/update_advanced"); |
||
| 36 | elgg_register_action("admin/site/update_advanced", dirname(__FILE__) . "/actions/admin/site/update_advanced.php", "admin"); |
||
| 37 | |||
| 38 | elgg_register_page_handler("register", "pleio_register_page_handler"); |
||
| 39 | elgg_register_page_handler("access_requested", "pleio_access_requested_page_handler"); |
||
| 40 | |||
| 41 | elgg_register_action("pleio/request_access", dirname(__FILE__) . "/actions/request_access.php", "public"); |
||
| 42 | elgg_register_action("admin/pleio/process_access", dirname(__FILE__) . "/actions/admin/process_access.php", "admin"); |
||
| 43 | |||
| 44 | elgg_register_plugin_hook_handler("public_pages", "walled_garden", "pleio_public_pages_handler"); |
||
| 45 | elgg_register_plugin_hook_handler("action", "admin/site/update_basic", "pleio_admin_update_basic_handler"); |
||
| 46 | |||
| 47 | // elgg_register_plugin_hook_handler("entity:icon:url", "user", "pleio_user_icon_url_handler"); |
||
| 48 | // elgg_register_admin_menu_item("administer", "access_requests", "users"); |
||
| 49 | // elgg_register_admin_menu_item("administer", "import", "users"); |
||
| 50 | |||
| 51 | elgg_register_action("admin/user/import_step1", dirname(__FILE__) . "/actions/admin/user/import_step1.php", "admin"); |
||
| 52 | elgg_register_action("admin/user/import_step2", dirname(__FILE__) . "/actions/admin/user/import_step2.php", "admin"); |
||
| 53 | |||
| 54 | elgg_extend_view("css/elgg", "pleio/css/site"); |
||
| 55 | elgg_extend_view("page/elements/head", "page/elements/topbar/fix"); |
||
| 56 | elgg_extend_view("page/elements/foot", "page/elements/stats"); |
||
| 57 | |||
| 58 | if ( elgg_is_active_plugin('web_services') ) { |
||
| 59 | elgg_ws_expose_function( |
||
| 60 | "pleio.verifyuser", |
||
| 61 | "pleio_verify_user_creds", |
||
| 62 | array( |
||
| 63 | "user" => array('type' => 'string', 'required' => true), |
||
| 64 | "password" => array('type' => 'string', 'required' => true) |
||
| 65 | ), |
||
| 66 | 'Verifies user credentials based on email and password.', |
||
| 67 | 'POST', |
||
| 68 | false, |
||
| 69 | false |
||
| 70 | ); |
||
| 71 | |||
| 72 | function pleio_verify_user_creds($user, $password) { |
||
| 73 | $user_entity = get_user_by_email($user)[0]; |
||
| 74 | |||
| 75 | if (!$user_entity) { |
||
| 76 | return json_encode(false); |
||
| 77 | } |
||
| 78 | |||
| 79 | $username = $user_entity->username; |
||
| 80 | $name = $user_entity->name; |
||
| 81 | |||
| 82 | $icon_time = $user_entity->icontime; |
||
| 83 | $avatar = false; |
||
| 84 | if ($icon_time) { |
||
| 85 | $avatar = elgg_get_site_url().'mod/profile/icondirect.php?lastcache='.$icon_time.'&joindate='.$user_entity->getTimeCreated().'&guid='.$user_entity->guid.'&size=master'; |
||
| 86 | } |
||
| 87 | $admin = elgg_is_admin_user($user_entity->guid); |
||
| 88 | $valid = elgg_authenticate($username, $password); |
||
| 89 | |||
| 90 | $return = array("name" => $name, "avatar" => $avatar, "valid" => $valid, "admin" => $admin); |
||
| 91 | |||
| 92 | return $return; |
||
| 93 | } |
||
| 94 | |||
| 95 | if( elgg_is_active_plugin('gcRegistration_invitation') ){ |
||
| 96 | elgg_ws_expose_function( |
||
| 97 | "pleio.invited", |
||
| 98 | "pleio_invited", |
||
| 99 | array( |
||
| 100 | "email" => array('type' => 'string', 'required' => true) |
||
| 101 | ), |
||
| 102 | 'Verifies email address is in invitation list.', |
||
| 103 | 'POST', |
||
| 104 | false, |
||
| 105 | false |
||
| 106 | ); |
||
| 107 | |||
| 108 | function pleio_invited($email) { |
||
| 109 | $valid = json_encode(false); |
||
| 110 | |||
| 111 | // Checks against the email invitation list... |
||
| 112 | $invitation_query = "SELECT email FROM email_invitations WHERE email = '{$email}'"; |
||
| 113 | $result = get_data($invitation_query); |
||
| 114 | |||
| 115 | if( count($result) > 0 ) |
||
| 116 | $valid = true; |
||
| 117 | |||
| 118 | return $valid; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 277 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.