Conditions | 15 |
Paths | 520 |
Total Lines | 65 |
Code Lines | 42 |
Lines | 13 |
Ratio | 20 % |
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 | $filter_data = json_decode($filters); |
||
121 | if (!empty($filter_data)) { |
||
122 | $params = array( |
||
123 | 'limit' => $limit, |
||
124 | 'offset' => $offset |
||
125 | ); |
||
126 | |||
127 | if ($filter_data->type) { |
||
128 | $params['metadata_name'] = 'user_type'; |
||
129 | $params['metadata_value'] = $filter_data->type; |
||
130 | } |
||
131 | if ($filter_data->name) { |
||
132 | $db_prefix = elgg_get_config('dbprefix'); |
||
133 | $params['joins'] = array("JOIN {$db_prefix}users_entity ue ON e.guid = ue.guid"); |
||
134 | $params['wheres'] = array("(ue.username LIKE '%" . $filter_data->name . "%' OR ue.name LIKE '%" . $filter_data->name . "%')"); |
||
135 | } |
||
136 | |||
137 | $members = $user_entity->listFriends('', $limit, $params); |
||
|
|||
138 | } else { |
||
139 | $members = $user_entity->listFriends('', $limit, array( |
||
140 | 'limit' => $limit, |
||
141 | 'offset' => $offset |
||
142 | )); |
||
143 | } |
||
144 | $members = json_decode($members); |
||
145 | |||
146 | $data = array(); |
||
147 | View Code Duplication | foreach ($members as $member) { |
|
148 | $member_obj = get_user($member->guid); |
||
149 | $member_data = get_user_block($member->guid, $lang); |
||
150 | |||
151 | $about = ""; |
||
152 | if ($member_obj->description) { |
||
153 | $about = strip_tags($member_obj->description, '<p>'); |
||
154 | $about = str_replace("<p> </p>", '', $about); |
||
155 | } |
||
156 | |||
157 | $member_data['about'] = $about; |
||
158 | $data[] = $member_data; |
||
159 | } |
||
160 | |||
161 | return $data; |
||
162 | } |
||
163 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.