| Conditions | 15 |
| Paths | 520 |
| Total Lines | 67 |
| Code Lines | 44 |
| Lines | 13 |
| Ratio | 19.4 % |
| 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 |
||
| 98 | function get_members_colleague($profileemail, $user, $limit, $offset, $filters, $lang) |
||
| 99 | { |
||
| 100 | $user_entity = is_numeric($profileemail) ? get_user($profileemail) : (strpos($profileemail, '@') !== false ? get_user_by_email($profileemail)[0] : get_user_by_username($profileemail)); |
||
| 101 | if (!$user_entity) { |
||
| 102 | return "User was not found. Please try a different GUID, username, or email address"; |
||
| 103 | } |
||
| 104 | if (!$user_entity instanceof ElggUser) { |
||
| 105 | return "Invalid user. Please try a different GUID, username, or email address"; |
||
| 106 | } |
||
| 107 | |||
| 108 | $viewer = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
||
| 109 | if (!$viewer) { |
||
| 110 | return "Viewer user was not found. Please try a different GUID, username, or email address"; |
||
| 111 | } |
||
| 112 | if (!$viewer instanceof ElggUser) { |
||
| 113 | return "Invalid viewer user. Please try a different GUID, username, or email address"; |
||
| 114 | } |
||
| 115 | |||
| 116 | if (!elgg_is_logged_in()) { |
||
| 117 | login($user_entity); |
||
| 118 | } |
||
| 119 | |||
| 120 | $defaults = array( |
||
| 121 | 'type' => 'user', |
||
| 122 | 'relationship' => 'friend', |
||
| 123 | 'relationship_guid' => $user_entity->getGUID(), |
||
| 124 | 'limit' => $limit, |
||
| 125 | 'offset' => $offset, |
||
| 126 | 'full_view' => false, |
||
| 127 | ); |
||
| 128 | |||
| 129 | $vars = array(); |
||
| 130 | $filter_data = json_decode($filters); |
||
| 131 | if (!empty($filter_data)) { |
||
| 132 | if ($filter_data->type) { |
||
| 133 | $vars['metadata_name'] = 'user_type'; |
||
| 134 | $vars['metadata_value'] = $filter_data->type; |
||
| 135 | } |
||
| 136 | if ($filter_data->name) { |
||
| 137 | $db_prefix = elgg_get_config('dbprefix'); |
||
| 138 | $vars['joins'] = array("JOIN {$db_prefix}users_entity ue ON e.guid = ue.guid"); |
||
| 139 | $vars['wheres'] = array("(ue.username LIKE '%" . $filter_data->name . "%' OR ue.name LIKE '%" . $filter_data->name . "%')"); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | $options = array_merge($defaults, $vars); |
||
| 144 | |||
| 145 | $members = elgg_list_entities_from_relationship($options); |
||
| 146 | $members = json_decode($members); |
||
| 147 | |||
| 148 | $data = array(); |
||
| 149 | View Code Duplication | foreach ($members as $member) { |
|
| 150 | $member_obj = get_user($member->guid); |
||
| 151 | $member_data = get_user_block($member->guid, $lang); |
||
| 152 | |||
| 153 | $about = ""; |
||
| 154 | if ($member_obj->description) { |
||
| 155 | $about = strip_tags($member_obj->description, '<p>'); |
||
| 156 | $about = str_replace("<p> </p>", '', $about); |
||
| 157 | } |
||
| 158 | |||
| 159 | $member_data['about'] = $about; |
||
| 160 | $data[] = $member_data; |
||
| 161 | } |
||
| 162 | |||
| 163 | return $data; |
||
| 164 | } |
||
| 165 |