Conditions | 16 |
Paths | 292 |
Total Lines | 70 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 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 |
||
205 | protected function processShift($entry, $request) |
||
206 | { |
||
207 | static $profile = null; |
||
208 | static $eeAvailable = false; |
||
209 | static $canDoRole = array(); |
||
210 | static $roles = array(); |
||
211 | if($this->isAdmin === null) |
||
212 | { |
||
213 | $this->isVolunteerAdmin($request); |
||
214 | } |
||
215 | if($profile === null) |
||
216 | { |
||
217 | $profile = new \VolunteerProfile($this->user->uid); |
||
218 | $eeAvailable = $profile->isEEAvailable(); |
||
219 | $dataTable = DataSetFactory::getDataTableByNames('fvs', 'roles'); |
||
220 | $tmp = $dataTable->read(); |
||
221 | foreach($tmp as $role) |
||
222 | { |
||
223 | $roles[$role['short_name']] = $role; |
||
224 | } |
||
225 | } |
||
226 | $this->cleanupNonDBFields($entry); |
||
227 | $shift = new \VolunteerShift(false, $entry); |
||
228 | $entry['isAdmin'] = $this->isAdminForShift($entry, $this->user); |
||
229 | $entry['overlap'] = $shift->findOverlaps($this->user->uid, true); |
||
230 | if(!$this->shouldShowDepartment($entry['departmentID'], $entry['isAdmin'])) |
||
231 | { |
||
232 | return null; |
||
233 | } |
||
234 | $entry['available'] = true; |
||
235 | $this->doShiftTimeChecks($shift, $entry); |
||
236 | if($entry['earlyLate'] != -1 && !$eeAvailable) |
||
237 | { |
||
238 | $entry['available'] = false; |
||
239 | $entry['why'] = 'Shift requires early entry or late stay and you have not provided your legal name'; |
||
240 | } |
||
241 | if(!isset($canDoRole[$entry['roleID']])) |
||
242 | { |
||
243 | $canDoRole[$entry['roleID']] = $this->canUserDoRole($profile, $roles[$entry['roleID']]); |
||
244 | } |
||
245 | if($canDoRole[$entry['roleID']] !== true) |
||
246 | { |
||
247 | $entry['available'] = false; |
||
248 | $entry['why'] = $canDoRole[$entry['roleID']]['whyMsg']; |
||
249 | $entry['whyClass'] = $canDoRole[$entry['roleID']]['whyClass']; |
||
250 | } |
||
251 | if($shift->isFilled()) |
||
252 | { |
||
253 | if(isset($entry['participant']) && ($entry['participant'] !== '/dev/null' || $entry['participant'] !== '')) |
||
254 | { |
||
255 | $entry['volunteer'] = $this->getParticipantDiplayName($entry['participant']); |
||
256 | } |
||
257 | if(isset($entry['participant']) && $entry['participant'] === $profile->uid) |
||
258 | { |
||
259 | $entry['available'] = false; |
||
260 | $entry['why'] = 'Shift is already taken, by you'; |
||
261 | $entry['whyClass'] = 'MINE'; |
||
262 | } |
||
263 | else |
||
264 | { |
||
265 | $entry['available'] = false; |
||
266 | $entry['why'] = 'Shift is already taken'; |
||
267 | $entry['whyClass'] = 'TAKEN'; |
||
268 | } |
||
269 | if(!$entry['isAdmin']) |
||
270 | { |
||
271 | unset($entry['participant']); |
||
272 | } |
||
273 | } |
||
274 | return $entry; |
||
275 | } |
||
288 |