| Conditions | 9 |
| Paths | 16 |
| Total Lines | 53 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 135 | public function toJsonLd() |
||
| 136 | { |
||
| 137 | $jsonLd = []; |
||
| 138 | |||
| 139 | $startDate = $this->getStartDate(); |
||
| 140 | $endDate = $this->getEndDate(); |
||
| 141 | |||
| 142 | $jsonLd['calendarType'] = $this->getType(); |
||
| 143 | // All calendar types allow startDate (and endDate). |
||
| 144 | // One timestamp - full day. |
||
| 145 | // One timestamp - start hour. |
||
| 146 | // One timestamp - start and end hour. |
||
| 147 | if (!empty($startDate)) { |
||
| 148 | $jsonLd['startDate'] = $startDate; |
||
| 149 | } |
||
| 150 | |||
| 151 | if (!empty($endDate)) { |
||
| 152 | $jsonLd['endDate'] = $endDate; |
||
| 153 | } |
||
| 154 | |||
| 155 | $timestamps = $this->getTimestamps(); |
||
| 156 | if (!empty($timestamps)) { |
||
| 157 | $jsonLd['subEvent'] = array(); |
||
| 158 | foreach ($timestamps as $timestamp) { |
||
| 159 | $jsonLd['subEvent'][] = array( |
||
| 160 | '@type' => 'Event', |
||
| 161 | 'startDate' => $timestamp->getStartDate(), |
||
| 162 | 'endDate' => $timestamp->getEndDate(), |
||
| 163 | ); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | // Period. |
||
| 168 | // Period with openingtimes. |
||
| 169 | // Permanent - "altijd open". |
||
| 170 | // Permanent - with openingtimes |
||
| 171 | $openingHours = $this->getOpeningHours(); |
||
| 172 | if (!empty($openingHours)) { |
||
| 173 | $jsonLd['openingHours'] = array(); |
||
| 174 | foreach ($openingHours as $openingHour) { |
||
| 175 | $schedule = array('dayOfWeek' => $openingHour->dayOfWeek); |
||
| 176 | if (!empty($openingHour->opens)) { |
||
| 177 | $schedule['opens'] = $openingHour->opens; |
||
| 178 | } |
||
| 179 | if (!empty($openingHour->closes)) { |
||
| 180 | $schedule['closes'] = $openingHour->closes; |
||
| 181 | } |
||
| 182 | $jsonLd['openingHours'][] = $schedule; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | return $jsonLd; |
||
| 187 | } |
||
| 188 | } |
||
| 189 |