| Conditions | 29 |
| Paths | > 20000 |
| Total Lines | 146 |
| Code Lines | 99 |
| Lines | 146 |
| Ratio | 100 % |
| 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 |
||
| 36 | View Code Duplication | function get_opportunity_test($user, $guid, $lang) |
|
| 37 | { |
||
| 38 | $user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user)); |
||
| 39 | if (!$user_entity) { |
||
| 40 | return "User was not found. Please try a different GUID, username, or email address"; |
||
| 41 | } |
||
| 42 | if (!$user_entity instanceof ElggUser) { |
||
| 43 | return "Invalid user. Please try a different GUID, username, or email address"; |
||
| 44 | } |
||
| 45 | |||
| 46 | if (!elgg_is_logged_in()) { |
||
| 47 | login($user_entity); |
||
| 48 | } |
||
| 49 | |||
| 50 | $entity = get_entity($guid); |
||
| 51 | if (!$entity) { |
||
| 52 | return "Opportunity was not found. Please try a different GUID"; |
||
| 53 | } |
||
| 54 | if (!elgg_instanceof($entity, 'object', 'mission')) { |
||
| 55 | return "Invalid opportunity. Please try a different GUID"; |
||
| 56 | } |
||
| 57 | |||
| 58 | |||
| 59 | |||
| 60 | $opportunities = elgg_list_entities(array( |
||
| 61 | 'type' => 'object', |
||
| 62 | 'subtype' => 'mission', |
||
| 63 | 'guid' => $guid |
||
| 64 | )); |
||
| 65 | $opportunity = json_decode($opportunities)[0]; |
||
| 66 | |||
| 67 | $opportunity->title = gc_explode_translation($opportunity->title, $lang); |
||
| 68 | |||
| 69 | $likes = elgg_get_annotations(array( |
||
| 70 | 'guid' => $opportunity->guid, |
||
| 71 | 'annotation_name' => 'likes' |
||
| 72 | )); |
||
| 73 | $opportunity->likes = count($likes); |
||
| 74 | |||
| 75 | $liked = elgg_get_annotations(array( |
||
| 76 | 'guid' => $opportunity->guid, |
||
| 77 | 'annotation_owner_guid' => $user_entity->guid, |
||
| 78 | 'annotation_name' => 'likes' |
||
| 79 | )); |
||
| 80 | $opportunity->liked = count($liked) > 0; |
||
| 81 | |||
| 82 | $opportunity->comments = get_entity_comments($opportunity->guid); |
||
| 83 | |||
| 84 | $opportunity->userDetails = get_user_block($opportunity->owner_guid, $lang); |
||
| 85 | $opportunity->description = gc_explode_translation($opportunity->description, $lang); |
||
| 86 | |||
| 87 | $opportunityObj = get_entity($opportunity->guid); |
||
| 88 | $opportunity->jobtype = elgg_echo($opportunityObj->job_type); |
||
| 89 | $opportunity->roletype = elgg_echo($opportunityObj->role_type); |
||
| 90 | //$opportunity->programArea = elgg_echo('missions:program_area') . ": " . elgg_echo($opportunityObj->program_area); //This should work and translate to user lang but doesnt |
||
| 91 | $opportunity->programArea = elgg_echo($opportunityObj->program_area); |
||
| 92 | $opportunity->numOpportunities = $opportunityObj->number; |
||
| 93 | $opportunity->idealStart = $opportunityObj->start_date; |
||
| 94 | $opportunity->idealComplete = $opportunityObj->complete_date; |
||
| 95 | $opportunity->deadline = $opportunityObj->deadline; |
||
| 96 | $opportunity->oppVirtual = $opportunityObj->remotely; |
||
| 97 | $opportunity->oppOnlyIn = $opportunityObj->openess; |
||
| 98 | $opportunity->location = elgg_echo($opportunityObj->location); |
||
| 99 | $opportunity->security = elgg_echo($opportunityObj->security); |
||
| 100 | $opportunity->skills = $opportunityObj->key_skills; |
||
| 101 | //$opportunity->participants = $opportunityObj->; |
||
| 102 | //$opportunity->applicants = $opportunityObj->; |
||
| 103 | $opportunity->timezone = elgg_echo($opportunityObj->timezone); |
||
| 104 | $opportunity->timecommitment = $opportunityObj->time_commitment; |
||
| 105 | $opportunity->department = $opportunityObj->department; |
||
| 106 | |||
| 107 | //Language metadata |
||
| 108 | $unpacked_array = mm_unpack_mission($opportunityObj); |
||
| 109 | $unpacked_language = ''; |
||
| 110 | if (! empty($unpacked_array['lwc_english']) || ! empty($unpacked_array['lwc_french'])) { |
||
| 111 | $unpacked_language .= '<b>' . elgg_echo('missions:written_comprehension') . ': </b>'; |
||
| 112 | if (! empty($unpacked_array['lwc_english'])) { |
||
| 113 | $unpacked_language .= '<span name="mission-lwc-english">' . elgg_echo('missions:formatted:english', array($unpacked_array['lwc_english'])) . '</span> '; |
||
| 114 | } |
||
| 115 | if (! empty($unpacked_array['lwc_french'])) { |
||
| 116 | $unpacked_language .= '<span name="mission-lwc-french">' . elgg_echo('missions:formatted:french', array($unpacked_array['lwc_french'])) . '</span>'; |
||
| 117 | } |
||
| 118 | $unpacked_language .= '<br>'; |
||
| 119 | } |
||
| 120 | if (! empty($unpacked_array['lwe_english']) || ! empty($unpacked_array['lwe_french'])) { |
||
| 121 | $unpacked_language .= '<b>' . elgg_echo('missions:written_expression') . ': </b>'; |
||
| 122 | if (! empty($unpacked_array['lwe_english'])) { |
||
| 123 | $unpacked_language .= '<span name="mission-lwe-english">' . elgg_echo('missions:formatted:english', array($unpacked_array['lwe_english'])) . '</span> '; |
||
| 124 | } |
||
| 125 | if (! empty($unpacked_array['lwe_french'])) { |
||
| 126 | $unpacked_language .= '<span name="mission-lwe-french">' . elgg_echo('missions:formatted:french', array($unpacked_array['lwe_french'])) . '</span>'; |
||
| 127 | } |
||
| 128 | $unpacked_language .= '<br>'; |
||
| 129 | } |
||
| 130 | if (! empty($unpacked_array['lop_english']) || ! empty($unpacked_array['lop_french'])) { |
||
| 131 | $unpacked_language .= '<b>' . elgg_echo('missions:oral_proficiency') . ': </b>'; |
||
| 132 | if (! empty($unpacked_array['lop_english'])) { |
||
| 133 | $unpacked_language .= '<span name="mission-lop-english">' . elgg_echo('missions:formatted:english', array($unpacked_array['lop_english'])) . '</span> '; |
||
| 134 | } |
||
| 135 | if (! empty($unpacked_array['lop_french'])) { |
||
| 136 | $unpacked_language .= '<span name="mission-lop-french">' . elgg_echo('missions:formatted:french', array($unpacked_array['lop_french'])) . '</span>'; |
||
| 137 | } |
||
| 138 | $unpacked_language .= '<br>'; |
||
| 139 | } |
||
| 140 | if (empty($unpacked_language)) { |
||
| 141 | $unpacked_language = '<span name="no-languages">' . elgg_echo('missions:none_required') . '</span>'; |
||
| 142 | } |
||
| 143 | $opportunity->languageRequirements = $unpacked_language; |
||
| 144 | |||
| 145 | //scheduling metadata |
||
| 146 | $unpacked_time = ''; |
||
| 147 | if ($opportunityObj->mon_start) { |
||
| 148 | $unpacked_time .= '<b>' . elgg_echo('missions:mon') . ': </b>'; |
||
| 149 | $unpacked_time .= $opportunityObj->mon_start . elgg_echo('missions:to') . $opportunityObj->mon_duration . '<br>'; |
||
| 150 | } |
||
| 151 | if ($opportunityObj->tue_start) { |
||
| 152 | $unpacked_time .= '<b>' . elgg_echo('missions:tue') . ': </b>'; |
||
| 153 | $unpacked_time .= '<span name="mission-tue-start">' . $opportunityObj->tue_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-tue-duration">' . $opportunityObj->tue_duration . '</span><br>'; |
||
| 154 | } |
||
| 155 | if ($opportunityObj->wed_start) { |
||
| 156 | $unpacked_time .= '<b>' . elgg_echo('missions:wed') . ': </b>'; |
||
| 157 | $unpacked_time .= $opportunityObj->wed_start . elgg_echo('missions:to') . $opportunityObj->wed_duration . '<br>'; |
||
| 158 | } |
||
| 159 | if ($opportunityObj->thu_start) { |
||
| 160 | $unpacked_time .= '<b>' . elgg_echo('missions:thu') . ': </b>'; |
||
| 161 | $unpacked_time .= '<span name="mission-thu-start">' . $opportunityObj->thu_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-thu-duration">' . $opportunityObj->thu_duration . '</span><br>'; |
||
| 162 | } |
||
| 163 | if ($opportunityObj->fri_start) { |
||
| 164 | $unpacked_time .= '<b>' . elgg_echo('missions:fri') . ': </b>'; |
||
| 165 | $unpacked_time .= '<span name="mission-fri-start">' . $opportunityObj->fri_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-fri-duration">' . $opportunityObj->fri_duration . '</span><br>'; |
||
| 166 | } |
||
| 167 | if ($opportunityObj->sat_start) { |
||
| 168 | $unpacked_time .= '<b>' . elgg_echo('missions:sat') . ': </b>'; |
||
| 169 | $unpacked_time .= '<span name="mission-sat-start">' . $opportunityObj->sat_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-sat-duration">' . $opportunityObj->sat_duration . '</span><br>'; |
||
| 170 | } |
||
| 171 | if ($opportunityObj->sun_start) { |
||
| 172 | $unpacked_time .= '<b>' . elgg_echo('missions:sun') . ': </b>'; |
||
| 173 | $unpacked_time .= '<span name="mission-sun-start">' . $opportunityObj->sun_start . '</span>' . elgg_echo('missions:to') . '<span name="mission-sun-duration">' . $opportunityObj->sun_duration . '</span><br>'; |
||
| 174 | } |
||
| 175 | if (empty($unpacked_time)) { |
||
| 176 | $unpacked_time = '<span name="no-times">' . elgg_echo('missions:none_required') . '</span>'; |
||
| 177 | } |
||
| 178 | $opportunity->schedulingRequirements = $unpacked_time; |
||
| 179 | |||
| 180 | return $opportunity; |
||
| 181 | } |
||
| 182 | |||
| 263 |