| Conditions | 13 |
| Paths | 292 |
| Total Lines | 70 |
| 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 |
||
| 173 | protected function processShift($entry, $request) |
||
| 174 | { |
||
| 175 | static $profile = null; |
||
| 176 | static $eeAvailable = false; |
||
| 177 | static $canDoRole = array(); |
||
| 178 | static $roles = array(); |
||
| 179 | if($this->isAdmin === null) |
||
| 180 | { |
||
| 181 | $this->isVolunteerAdmin($request); |
||
| 182 | } |
||
| 183 | if($profile === null) |
||
| 184 | { |
||
| 185 | $profile = new \VolunteerProfile($this->user->uid); |
||
| 186 | $eeAvailable = $profile->isEEAvailable(); |
||
| 187 | $dataTable = DataSetFactory::getDataTableByNames('fvs', 'roles'); |
||
| 188 | $tmp = $dataTable->read(); |
||
| 189 | foreach($tmp as $role) |
||
|
|
|||
| 190 | { |
||
| 191 | $roles[$role['short_name']] = $role; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | $shift = new \VolunteerShift(false, $entry); |
||
| 195 | $entry['isAdmin'] = $this->isAdminForShift($entry, $this->user); |
||
| 196 | $entry['overlap'] = $shift->findOverlaps($this->user->uid, true); |
||
| 197 | if(!$this->shouldShowDepartment($entry['departmentID'], $entry['isAdmin'])) |
||
| 198 | { |
||
| 199 | return null; |
||
| 200 | } |
||
| 201 | $entry['available'] = true; |
||
| 202 | $this->doShiftTimeChecks($shift, $entry); |
||
| 203 | if($entry['earlyLate'] != -1 && !$eeAvailable) |
||
| 204 | { |
||
| 205 | $entry['available'] = false; |
||
| 206 | $entry['why'] = 'Shift requires early entry or late stay and you have not provided your legal name'; |
||
| 207 | } |
||
| 208 | if(!isset($canDoRole[$entry['roleID']])) |
||
| 209 | { |
||
| 210 | $canDoRole[$entry['roleID']] = $this->canUserDoRole($profile, $roles[$entry['roleID']]); |
||
| 211 | } |
||
| 212 | if($canDoRole[$entry['roleID']] !== true) |
||
| 213 | { |
||
| 214 | $entry['available'] = false; |
||
| 215 | $entry['why'] = $canDoRole[$entry['roleID']]['whyMsg']; |
||
| 216 | $entry['whyClass'] = $canDoRole[$entry['roleID']]['whyClass']; |
||
| 217 | } |
||
| 218 | if($shift->isFilled()) |
||
| 219 | { |
||
| 220 | if($entry['participant'] !== '/dev/null') |
||
| 221 | { |
||
| 222 | $entry['volunteer'] = $this->getParticipantDiplayName($entry['participant']); |
||
| 223 | } |
||
| 224 | if($entry['participant'] === $profile->uid) |
||
| 225 | { |
||
| 226 | $entry['available'] = false; |
||
| 227 | $entry['why'] = 'Shift is already taken, by you'; |
||
| 228 | $entry['whyClass'] = 'MINE'; |
||
| 229 | } |
||
| 230 | else |
||
| 231 | { |
||
| 232 | $entry['available'] = false; |
||
| 233 | $entry['why'] = 'Shift is already taken'; |
||
| 234 | $entry['whyClass'] = 'TAKEN'; |
||
| 235 | } |
||
| 236 | if(!$entry['isAdmin']) |
||
| 237 | { |
||
| 238 | unset($entry['participant']); |
||
| 239 | } |
||
| 240 | } |
||
| 241 | return $entry; |
||
| 242 | } |
||
| 243 | |||
| 255 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.