| Conditions | 8 |
| Paths | 2 |
| Total Lines | 57 |
| Code Lines | 33 |
| 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 |
||
| 93 | private function getWeekscheme(CalendarInterface $itemCalendar) |
||
| 94 | { |
||
| 95 | // Store opening hours. |
||
| 96 | $openingHours = $itemCalendar->getOpeningHours(); |
||
| 97 | $weekscheme = null; |
||
| 98 | |||
| 99 | if (!empty($openingHours)) { |
||
| 100 | $weekscheme = new CultureFeed_Cdb_Data_Calendar_Weekscheme(); |
||
| 101 | |||
| 102 | // Multiple opening times can happen on same day. Store them in array. |
||
| 103 | $openingTimesPerDay = array( |
||
| 104 | 'monday' => array(), |
||
| 105 | 'tuesday' => array(), |
||
| 106 | 'wednesday' => array(), |
||
| 107 | 'thursday' => array(), |
||
| 108 | 'friday' => array(), |
||
| 109 | 'saturday' => array(), |
||
| 110 | 'sunday' => array(), |
||
| 111 | ); |
||
| 112 | |||
| 113 | foreach ($openingHours as $openingHour) { |
||
| 114 | // In CDB2 every day needs to be a seperate entry. |
||
| 115 | if (is_array($openingHour)) { |
||
| 116 | $openingHour = (object) $openingHour; |
||
| 117 | } |
||
| 118 | foreach ($openingHour->getDayOfWeekCollection()->getDaysOfWeek() as $day) { |
||
| 119 | $openingTimesPerDay[$day->toNative()][] = new CultureFeed_Cdb_Data_Calendar_OpeningTime( |
||
| 120 | $openingHour->getOpens()->toNativeString() . ':00', |
||
| 121 | $openingHour->getCloses()->toNativeString() . ':00' |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | // Create the opening times correctly |
||
| 127 | foreach ($openingTimesPerDay as $day => $openingTimes) { |
||
| 128 | // Empty == closed. |
||
| 129 | if (empty($openingTimes)) { |
||
| 130 | $openingInfo = new CultureFeed_Cdb_Data_Calendar_SchemeDay( |
||
| 131 | $day, |
||
| 132 | CultureFeed_Cdb_Data_Calendar_SchemeDay::SCHEMEDAY_OPEN_TYPE_CLOSED |
||
| 133 | ); |
||
| 134 | } else { |
||
| 135 | // Add all opening times. |
||
| 136 | $openingInfo = new CultureFeed_Cdb_Data_Calendar_SchemeDay( |
||
| 137 | $day, |
||
| 138 | CultureFeed_Cdb_Data_Calendar_SchemeDay::SCHEMEDAY_OPEN_TYPE_OPEN |
||
| 139 | ); |
||
| 140 | foreach ($openingTimes as $openingTime) { |
||
| 141 | $openingInfo->addOpeningTime($openingTime); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | $weekscheme->setDay($day, $openingInfo); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | return $weekscheme; |
||
| 149 | } |
||
| 150 | |||
| 182 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.