| Conditions | 10 |
| Paths | 16 |
| Total Lines | 47 |
| Code Lines | 35 |
| 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 |
||
| 35 | public function encode($data, $format, array $context = array()) |
||
| 36 | { |
||
| 37 | $calendar = $data instanceof CalendarInterface ? $data : Calendar::deserialize($data); |
||
| 38 | |||
| 39 | $weekscheme = $this->getWeekscheme($calendar); |
||
| 40 | |||
| 41 | switch ($calendar->getType()->toNative()) { |
||
| 42 | case CalendarType::MULTIPLE: |
||
| 43 | $cdbCalendar = new CultureFeed_Cdb_Data_Calendar_TimestampList(); |
||
| 44 | foreach ($calendar->getTimestamps() as $timestamp) { |
||
| 45 | $this->timestampCalendar( |
||
| 46 | $timestamp->getStartDate(), |
||
| 47 | $timestamp->getEndDate(), |
||
| 48 | $cdbCalendar |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | break; |
||
| 52 | case CalendarType::SINGLE: |
||
| 53 | $cdbCalendar = $this->timestampCalendar( |
||
| 54 | $calendar->getStartDate(), |
||
| 55 | $calendar->getEndDate(), |
||
| 56 | new CultureFeed_Cdb_Data_Calendar_TimestampList() |
||
| 57 | ); |
||
| 58 | break; |
||
| 59 | case CalendarType::PERIODIC: |
||
| 60 | $cdbCalendar = new CultureFeed_Cdb_Data_Calendar_PeriodList(); |
||
| 61 | $startDate = $calendar->getStartDate()->format('Y-m-d'); |
||
| 62 | $endDate = $calendar->getEndDate()->format('Y-m-d'); |
||
| 63 | |||
| 64 | $period = new CultureFeed_Cdb_Data_Calendar_Period($startDate, $endDate); |
||
| 65 | if (!empty($weekscheme) && !empty($weekscheme->getDays())) { |
||
| 66 | $period->setWeekScheme($weekscheme); |
||
| 67 | } |
||
| 68 | $cdbCalendar->add($period); |
||
| 69 | break; |
||
| 70 | case CalendarType::PERMANENT: |
||
| 71 | $cdbCalendar = new CultureFeed_Cdb_Data_Calendar_Permanent(); |
||
| 72 | if (!empty($weekscheme)) { |
||
| 73 | $cdbCalendar->setWeekScheme($weekscheme); |
||
| 74 | } |
||
| 75 | break; |
||
| 76 | default: |
||
| 77 | $cdbCalendar = new CultureFeed_Cdb_Data_Calendar_Permanent(); |
||
| 78 | } |
||
| 79 | |||
| 80 | return $cdbCalendar; |
||
| 81 | } |
||
| 82 | |||
| 182 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.