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 |
||
76 | private function getWeekScheme(CalendarInterface $itemCalendar) |
||
77 | { |
||
78 | // Store opening hours. |
||
79 | $openingHours = $itemCalendar->getOpeningHours(); |
||
80 | $weekScheme = null; |
||
81 | |||
82 | if (!empty($openingHours)) { |
||
83 | $weekScheme = new CultureFeed_Cdb_Data_Calendar_Weekscheme(); |
||
84 | |||
85 | // Multiple opening times can happen on same day. Store them in array. |
||
86 | $openingTimesPerDay = array( |
||
87 | 'monday' => array(), |
||
88 | 'tuesday' => array(), |
||
89 | 'wednesday' => array(), |
||
90 | 'thursday' => array(), |
||
91 | 'friday' => array(), |
||
92 | 'saturday' => array(), |
||
93 | 'sunday' => array(), |
||
94 | ); |
||
95 | |||
96 | foreach ($openingHours as $openingHour) { |
||
97 | // In CDB2 every day needs to be a seperate entry. |
||
98 | if (is_array($openingHour)) { |
||
99 | $openingHour = (object) $openingHour; |
||
100 | } |
||
101 | foreach ($openingHour->getDayOfWeekCollection()->getDaysOfWeek() as $day) { |
||
102 | $openingTimesPerDay[$day->toNative()][] = new CultureFeed_Cdb_Data_Calendar_OpeningTime( |
||
103 | $openingHour->getOpens()->toNativeString() . ':00', |
||
104 | $openingHour->getCloses()->toNativeString() . ':00' |
||
105 | ); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | // Create the opening times correctly |
||
110 | foreach ($openingTimesPerDay as $day => $openingTimes) { |
||
111 | // Empty == closed. |
||
112 | if (empty($openingTimes)) { |
||
113 | $openingInfo = new CultureFeed_Cdb_Data_Calendar_SchemeDay( |
||
114 | $day, |
||
115 | CultureFeed_Cdb_Data_Calendar_SchemeDay::SCHEMEDAY_OPEN_TYPE_CLOSED |
||
116 | ); |
||
117 | } else { |
||
118 | // Add all opening times. |
||
119 | $openingInfo = new CultureFeed_Cdb_Data_Calendar_SchemeDay( |
||
120 | $day, |
||
121 | CultureFeed_Cdb_Data_Calendar_SchemeDay::SCHEMEDAY_OPEN_TYPE_OPEN |
||
122 | ); |
||
123 | foreach ($openingTimes as $openingTime) { |
||
124 | $openingInfo->addOpeningTime($openingTime); |
||
125 | } |
||
126 | } |
||
127 | $weekScheme->setDay($day, $openingInfo); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | return $weekScheme; |
||
132 | } |
||
133 | |||
165 |