| Conditions | 7 |
| Paths | 16 |
| Total Lines | 80 |
| Code Lines | 42 |
| Lines | 5 |
| Ratio | 6.25 % |
| 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 |
||
| 169 | private function Calendar($dates, Calendar $currentCalendar) |
||
| 170 | { |
||
| 171 | |||
| 172 | // 1) Single Values |
||
| 173 | |||
| 174 | $calendar['InnerClass'] = $this->innerClass; |
||
| 175 | $calendar['TimeTitle'] = $this->timeTitle; |
||
| 176 | |||
| 177 | // 2) Days Values |
||
| 178 | |||
| 179 | View Code Duplication | foreach ($dates as $date) { |
|
| 180 | $dayTitleClass = eval($this->dayTitleClass); |
||
| 181 | $dayTitle = eval($this->dayTitle); |
||
| 182 | $days[] = new ArrayData(array('DayTitleClass' => $dayTitleClass, 'DayTitle' => $dayTitle)); |
||
| 183 | } |
||
| 184 | |||
| 185 | $calendar['Days'] = new ArrayList($days); |
||
| 186 | |||
| 187 | // 3) Periods Values |
||
| 188 | |||
| 189 | $subPeriods = $this->getSubPeriods(); |
||
| 190 | |||
| 191 | $todayNow = mktime(); |
||
| 192 | |||
| 193 | foreach ($subPeriods as $subPeriod) { |
||
| 194 | $period = array(); |
||
| 195 | |||
| 196 | $subPeriodStartTime = $subPeriod->getStartTime(); |
||
| 197 | $subPeriodEndTime = $subPeriod->getEndTime(); |
||
| 198 | |||
| 199 | $subPeriodStartTimeHours = $subPeriodStartTime->getHours(); |
||
| 200 | $subPeriodEndTimeHours = $subPeriodEndTime->getHours(); |
||
| 201 | |||
| 202 | $subPeriodStartTimeMinutes = $subPeriodStartTime->getMinutes(); |
||
| 203 | $subPeriodEndTimeMinutes = $subPeriodEndTime->getMinutes(); |
||
| 204 | |||
| 205 | $subPeriodStartTimeSeconds = $subPeriodStartTime->getSeconds(); |
||
| 206 | $subPeriodEndTimeSeconds = $subPeriodEndTime->getSeconds(); |
||
| 207 | |||
| 208 | $subPeriodStartDateTime = mktime($subPeriodStartTimeHours, $subPeriodStartTimeMinutes, $subPeriodStartTimeSeconds, 0, 0, 0); |
||
| 209 | $subPeriodEndDateTime = mktime($subPeriodEndTimeHours, $subPeriodEndTimeMinutes, $subPeriodEndTimeSeconds, 0, 0, 0); |
||
| 210 | |||
| 211 | // 1) Single Values |
||
| 212 | |||
| 213 | $period['TimeClass'] = eval($this->timeClass); |
||
| 214 | $period['Time'] = eval($this->time); |
||
| 215 | |||
| 216 | // 2) Days Values |
||
| 217 | |||
| 218 | $days = array(); |
||
| 219 | |||
| 220 | foreach ($dates as $date) { |
||
| 221 | $day = date('j', $date); |
||
| 222 | $month = date('n', $date); |
||
| 223 | $year = date('Y', $date); |
||
| 224 | |||
| 225 | $subPeriodStart = mktime($subPeriodStartTimeHours, $subPeriodStartTimeMinutes, $subPeriodStartTimeSeconds, $month, $day, $year); |
||
| 226 | $subPeriodEnd = mktime($subPeriodEndTimeHours, $subPeriodEndTimeMinutes, $subPeriodEndTimeSeconds, $month, $day, $year); |
||
| 227 | |||
| 228 | $subPeriodParams = array(); |
||
| 229 | |||
| 230 | $subPeriodParams['IsTodayNow'] = $subPeriodStart <= $todayNow && $todayNow <= $subPeriodEnd; |
||
| 231 | $subPeriodParams['IsToday'] = $day == date('j') && $month == date('n') && $year == date('Y'); |
||
| 232 | $subPeriodParams['IsPast'] = $subPeriodStart < $todayNow; |
||
| 233 | $subPeriodParams['DayClass'] = eval($this->dayClass); |
||
| 234 | |||
| 235 | $this->extend('updateSubPeriodParams', $subPeriodStart, $subPeriodEnd, $subPeriodParams, $currentCalendar); |
||
| 236 | |||
| 237 | $days[] = new ArrayData($subPeriodParams); |
||
| 238 | } |
||
| 239 | |||
| 240 | $period['Days'] = new ArrayList($days); |
||
| 241 | |||
| 242 | $periods[] = new ArrayData($period); |
||
| 243 | } |
||
| 244 | |||
| 245 | $calendar['Periods'] = new ArrayList($periods); |
||
| 246 | |||
| 247 | return new ArrayData($calendar); |
||
| 248 | } |
||
| 249 | } |
||
| 250 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.