Conditions | 20 |
Paths | 165 |
Total Lines | 169 |
Code Lines | 96 |
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 |
||
249 | return null; |
||
250 | } |
||
251 | |||
252 | public function sync(Log $log) |
||
253 | { |
||
254 | try { |
||
255 | $api->get($this->getContext()->getVerificationUrl()); |
||
256 | } catch (Exception $e) { |
||
257 | $this->logThrow(new Exception("Cannot sync calendars without a valid Canvas context"), $log); |
||
258 | } |
||
259 | |||
260 | if (!DataUtilities::URLexists($this>getFeedUrl())) { |
||
261 | $this->logThrow(new Exception("Cannot sync calendars with a valid calendar feed"), $log); |
||
262 | } |
||
263 | |||
264 | $this->log(static::getTimestamp() . ' sync started', $log); |
||
265 | |||
266 | $this->save(); |
||
267 | |||
268 | $ics = new vcalendar([ |
||
269 | 'unique_id' => __FILE__, |
||
270 | 'url' => $this->getFeedUrl() |
||
271 | ]); |
||
272 | $ics->parse(); |
||
273 | |||
274 | /* |
||
275 | * TODO: would it be worth the performance improvement to just process |
||
276 | * things from today's date forward? (i.e. ignore old items, even |
||
277 | * if they've changed...) |
||
278 | */ |
||
279 | /* |
||
280 | * TODO:0 the best window for syncing would be the term of the course |
||
281 | * in question, right? issue:12 |
||
282 | */ |
||
283 | /* |
||
284 | * TODO:0 Arbitrarily selecting events in for a year on either side of |
||
285 | * today's date, probably a better system? issue:12 |
||
286 | */ |
||
287 | foreach ($ics->selectComponents( |
||
288 | date('Y')-1, // startYear |
||
289 | date('m'), // startMonth |
||
290 | date('d'), // startDay |
||
291 | date('Y')+1, // endYEar |
||
292 | date('m'), // endMonth |
||
293 | date('d'), // endDay |
||
294 | 'vevent', // cType |
||
295 | false, // flat |
||
296 | true, // any |
||
297 | true // split |
||
298 | ) as $year) { |
||
299 | foreach ($year as $month => $days) { |
||
300 | foreach ($days as $day => $events) { |
||
301 | foreach ($events as $i => $_event) { |
||
302 | try { |
||
303 | $event = new Event($_event, $this); |
||
304 | if ($this->getFilter()->filter($event)) { |
||
305 | $event->save(); |
||
306 | } else { |
||
307 | $event->delete(); |
||
308 | } |
||
309 | } catch (Exception $e) { |
||
310 | $this->logThrow($e, $log); |
||
311 | } |
||
312 | } |
||
313 | } |
||
314 | } |
||
315 | } |
||
316 | |||
317 | try { |
||
318 | Event::purgeUnmatched(static::getTimestamp(), $this); |
||
319 | } catch (Exception $e) { |
||
320 | $this->logThrow($e, $log); |
||
321 | } |
||
322 | |||
323 | $this->log(static::getTimestamp() . ' sync finished', $log); |
||
324 | } |
||
325 | |||
326 | private function log($message, Log $log, $flag = PEAR_LOG_INFO) |
||
327 | { |
||
328 | if ($log) { |
||
329 | $log->log($message, $flag); |
||
330 | } |
||
331 | } |
||
332 | |||
333 | private function logThrow( |
||
334 | Exception $exception, |
||
335 | Log $log, |
||
336 | $flag = PEAR_LOG_ERR |
||
337 | ) { |
||
338 | if ($log) { |
||
339 | $log->log($e->getMessage() . ': ' . $e->getTraceAsString(), $flag); |
||
340 | } else { |
||
341 | throw $e; |
||
342 | } |
||
343 | } |
||
344 | } |
||
345 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.