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