| Conditions | 21 |
| Paths | 484 |
| Total Lines | 94 |
| 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 |
||
| 147 | protected function processShift($entry, $request) |
||
| 148 | { |
||
| 149 | static $profile = null; |
||
| 150 | static $eeAvailable = false; |
||
| 151 | static $privateDepts = array(); |
||
| 152 | static $canDoRole = array(); |
||
| 153 | static $roles = array(); |
||
| 154 | if($profile === null) |
||
| 155 | { |
||
| 156 | $dataTable = DataSetFactory::getDataTableByNames('fvs', 'participants'); |
||
| 157 | $uid = $this->user->uid; |
||
| 158 | $filter = new \Data\Filter("uid eq '$uid'"); |
||
| 159 | $profile = $dataTable->read($filter); |
||
| 160 | if(empty($profile) && !$this->isAdmin) |
||
| 161 | { |
||
| 162 | return null; |
||
| 163 | } |
||
| 164 | $profile = $profile[0]; |
||
| 165 | if(isset($profile['firstName']) && isset($profile['lastName'])) |
||
| 166 | { |
||
| 167 | $eeAvailable = true; |
||
| 168 | } |
||
| 169 | $dataTable = DataSetFactory::getDataTableByNames('fvs', 'departments'); |
||
| 170 | $filter = new \Data\Filter('public eq false'); |
||
| 171 | $depts = $dataTable->read($filter); |
||
| 172 | foreach($depts as $dept) |
||
| 173 | { |
||
| 174 | array_push($privateDepts, $dept['departmentID']); |
||
| 175 | } |
||
| 176 | $dataTable = DataSetFactory::getDataTableByNames('fvs', 'roles'); |
||
| 177 | $tmp = $dataTable->read(); |
||
| 178 | foreach($tmp as $role) |
||
| 179 | { |
||
| 180 | $roles[$role['short_name']] = $role; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | $shift = new \VolunteerShift(false, $entry); |
||
| 184 | $entry['isAdmin'] = $this->isAdminForShift($entry, $this->user); |
||
| 185 | $entry['overlap'] = $shift->findOverlaps($this->user->uid, true); |
||
| 186 | if(in_array($entry['departmentID'], $privateDepts) && !$entry['isAdmin']) |
||
| 187 | { |
||
| 188 | return null; |
||
| 189 | } |
||
| 190 | $entry['available'] = true; |
||
| 191 | $endTime = new DateTime($entry['endTime']); |
||
| 192 | $startTime = new DateTime($entry['startTime']); |
||
| 193 | $now = new DateTime(); |
||
| 194 | if($startTime < $now) |
||
| 195 | { |
||
| 196 | $entry['available'] = false; |
||
| 197 | $entry['why'] = 'Shift already started'; |
||
| 198 | } |
||
| 199 | if($endTime < $now) |
||
| 200 | { |
||
| 201 | $entry['available'] = false; |
||
| 202 | $entry['why'] = 'Shift already ended'; |
||
| 203 | } |
||
| 204 | if($entry['earlyLate'] != -1 && !$eeAvailable) |
||
| 205 | { |
||
| 206 | $entry['available'] = false; |
||
| 207 | $entry['why'] = 'Shift requires early entry or late stay and you have not provided your legal name'; |
||
| 208 | } |
||
| 209 | if(!isset($canDoRole[$entry['roleID']])) |
||
| 210 | { |
||
| 211 | $canDoRole[$entry['roleID']] = $this->canUserDoRole($profile, $roles[$entry['roleID']]); |
||
| 212 | } |
||
| 213 | if($canDoRole[$entry['roleID']] !== true) |
||
| 214 | { |
||
| 215 | $entry['available'] = false; |
||
| 216 | $entry['why'] = $canDoRole[$entry['roleID']]['whyMsg']; |
||
| 217 | $entry['whyClass'] = $canDoRole[$entry['roleID']]['whyClass']; |
||
| 218 | } |
||
| 219 | if(isset($entry['status']) && ($entry['status'] === 'pending' || $entry['status'] === 'filled')) |
||
| 220 | { |
||
| 221 | $entry['volunteer'] = $this->getParticipantDiplayName($entry['participant']); |
||
| 222 | if($entry['participant'] === $profile['uid']) |
||
| 223 | { |
||
| 224 | $entry['available'] = false; |
||
| 225 | $entry['why'] = 'Shift is already taken, by you'; |
||
| 226 | $entry['whyClass'] = 'MINE'; |
||
| 227 | } |
||
| 228 | else |
||
| 229 | { |
||
| 230 | $entry['available'] = false; |
||
| 231 | $entry['why'] = 'Shift is already taken'; |
||
| 232 | $entry['whyClass'] = 'TAKEN'; |
||
| 233 | } |
||
| 234 | if(!$entry['isAdmin']) |
||
| 235 | { |
||
| 236 | unset($entry['participant']); |
||
| 237 | } |
||
| 238 | } |
||
| 239 | return $entry; |
||
| 240 | } |
||
| 241 | |||
| 249 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: