| Conditions | 8 |
| Paths | 36 |
| Total Lines | 52 |
| 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 |
||
| 19 | protected function createPDFBody() |
||
| 20 | { |
||
| 21 | $html = '<body>'; |
||
| 22 | $html .= '<style type="text/css">table {border-collapse: collapse;} table, th, td {border: 1px solid black;}</style>'; |
||
| 23 | $html .= '<h1 style="text-align: center;">'.$this->department['departmentName'].' Shift Schedule</h1>'; |
||
| 24 | //Group shifts by day... |
||
| 25 | $days = array(); |
||
| 26 | $shifts = $this->shifts; |
||
| 27 | $count = count($shifts); |
||
| 28 | for($i = 0; $i < $count; $i++) |
||
| 29 | { |
||
| 30 | $start = new \DateTime($shifts[$i]['startTime']); |
||
| 31 | $end = new \DateTime($shifts[$i]['endTime']); |
||
| 32 | $shifts[$i]['startTime'] = $start; |
||
| 33 | $shifts[$i]['endTime'] = $end; |
||
| 34 | $dateStr = $start->format('l (n/j/Y)'); |
||
| 35 | $timeStr = $start->format('g:i A').' till '.$end->format('g:i A'); |
||
| 36 | if(strlen($shifts[$i]['name']) > 0) |
||
| 37 | { |
||
| 38 | $timeStr .=' - <i>'.$shifts[$i]['name'].'</i>'; |
||
| 39 | } |
||
| 40 | if(!isset($days[$dateStr])) |
||
| 41 | { |
||
| 42 | $days[$dateStr] = array(); |
||
| 43 | } |
||
| 44 | if(!isset($days[$dateStr][$timeStr])) |
||
| 45 | { |
||
| 46 | $days[$dateStr][$timeStr] = array(); |
||
| 47 | } |
||
| 48 | array_push($days[$dateStr][$timeStr], $shifts[$i]); |
||
| 49 | } |
||
| 50 | ksort($days); |
||
| 51 | foreach($days as $dateStr=>$day) |
||
| 52 | { |
||
| 53 | $html .='<h2>'.$dateStr.'</h2>'; |
||
| 54 | uksort($day, array($this, 'groupSort')); |
||
| 55 | foreach($day as $shiftStr=>$shifts) |
||
| 56 | { |
||
| 57 | usort($shifts, array($this, 'shiftSort')); |
||
| 58 | $html .='<h3>'.$shiftStr.'</h3>'; |
||
| 59 | $html .='<table width="100%"><tr><th style="width: 20%">Role</th><th>Volunteer Name</th><th>Volunteer Camp</th></tr>'; |
||
| 60 | foreach($shifts as $shift) |
||
| 61 | { |
||
| 62 | //TODO Volunteer info for shift... |
||
| 63 | $html .='<tr><td>'.$this->getRoleNameFromID($shift['roleID']).'</td><td></td><td></td></tr>'; |
||
| 64 | } |
||
| 65 | $html .='</table>'; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | $html .='</body>'; |
||
| 69 | $this->setPDFFromHTML($html); |
||
| 70 | } |
||
| 71 | } |
||
| 72 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.