| Conditions | 11 |
| Paths | 82 |
| Total Lines | 63 |
| 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 |
||
| 142 | protected function processShift($entry) |
||
| 143 | { |
||
| 144 | static $profile = null; |
||
| 145 | static $eeAvailable = false; |
||
| 146 | static $canDoRole = array(); |
||
| 147 | static $roles = array(); |
||
| 148 | if($profile === null) |
||
| 149 | { |
||
| 150 | $profile = new \VolunteerProfile($this->user->uid); |
||
|
1 ignored issue
–
show
|
|||
| 151 | $eeAvailable = $profile->isEEAvailable(); |
||
| 152 | $dataTable = DataSetFactory::getDataTableByNames('fvs', 'roles'); |
||
| 153 | $tmp = $dataTable->read(); |
||
| 154 | foreach($tmp as $role) |
||
| 155 | { |
||
| 156 | $roles[$role['short_name']] = $role; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | $shift = new \VolunteerShift(false, $entry); |
||
| 160 | $entry['isAdmin'] = $this->isAdminForShift($entry, $this->user); |
||
| 161 | $entry['overlap'] = $shift->findOverlaps($this->user->uid, true); |
||
| 162 | if(!$this->shouldShowDepartment($entry['departmentID'], $entry['isAdmin'])) |
||
| 163 | { |
||
| 164 | return null; |
||
| 165 | } |
||
| 166 | $entry['available'] = true; |
||
| 167 | $this->doShiftTimeChecks($shift, $entry); |
||
| 168 | if($entry['earlyLate'] != -1 && !$eeAvailable) |
||
| 169 | { |
||
| 170 | $entry['available'] = false; |
||
| 171 | $entry['why'] = 'Shift requires early entry or late stay and you have not provided your legal name'; |
||
| 172 | } |
||
| 173 | if(!isset($canDoRole[$entry['roleID']])) |
||
| 174 | { |
||
| 175 | $canDoRole[$entry['roleID']] = $this->canUserDoRole($profile, $roles[$entry['roleID']]); |
||
| 176 | } |
||
| 177 | if($canDoRole[$entry['roleID']] !== true) |
||
| 178 | { |
||
| 179 | $entry['available'] = false; |
||
| 180 | $entry['why'] = $canDoRole[$entry['roleID']]['whyMsg']; |
||
| 181 | $entry['whyClass'] = $canDoRole[$entry['roleID']]['whyClass']; |
||
| 182 | } |
||
| 183 | if($shift->isFilled()) |
||
| 184 | { |
||
| 185 | $entry['volunteer'] = $this->getParticipantDiplayName($entry['participant']); |
||
| 186 | if($entry['participant'] === $profile->uid) |
||
| 187 | { |
||
| 188 | $entry['available'] = false; |
||
| 189 | $entry['why'] = 'Shift is already taken, by you'; |
||
| 190 | $entry['whyClass'] = 'MINE'; |
||
| 191 | } |
||
| 192 | else |
||
| 193 | { |
||
| 194 | $entry['available'] = false; |
||
| 195 | $entry['why'] = 'Shift is already taken'; |
||
| 196 | $entry['whyClass'] = 'TAKEN'; |
||
| 197 | } |
||
| 198 | if(!$entry['isAdmin']) |
||
| 199 | { |
||
| 200 | unset($entry['participant']); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | return $entry; |
||
| 204 | } |
||
| 205 | |||
| 213 |
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: