| Conditions | 9 |
| Paths | 29 |
| Total Lines | 52 |
| 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 |
||
| 29 | function caldav_onBeforePeriodsCreated(bab_eventBeforePeriodsCreated $event) |
||
| 30 | { |
||
| 31 | |||
| 32 | |||
| 33 | if (!is_array($event->periods->calendars)) { |
||
| 34 | return; |
||
| 35 | } |
||
| 36 | |||
| 37 | if (!$event->periods->isPeriodCollection('bab_CalendarEventCollection')) { |
||
| 38 | return; |
||
| 39 | } |
||
| 40 | |||
| 41 | /* @var $backend Func_CalendarBackend_Caldav */ |
||
| 42 | $backend = bab_functionality::get('CalendarBackend/Caldav'); |
||
| 43 | |||
| 44 | $oneCalendar = false; |
||
| 45 | foreach($event->periods->calendars as $calendar) |
||
| 46 | { |
||
| 47 | if ($calendar->getBackend() instanceof $backend) |
||
| 48 | { |
||
| 49 | $oneCalendar= true; |
||
| 50 | break; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | |||
| 55 | if (!$oneCalendar) |
||
| 56 | { |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | |||
| 63 | $criteria = $event->getCriteria(); |
||
| 64 | |||
| 65 | $beginDate = $event->getBeginDate(); |
||
| 66 | if ($beginDate instanceof BAB_DateTime) { |
||
| 67 | $criteria = $criteria->_AND_(bab_PeriodCriteriaFactory::Begin($event->getBeginDate())); |
||
| 68 | } |
||
| 69 | $endDate = $event->getEndDate(); |
||
| 70 | if ($endDate instanceof BAB_DateTime) { |
||
| 71 | $criteria = $criteria->_AND_(bab_PeriodCriteriaFactory::End($event->getEndDate())); |
||
| 72 | } |
||
| 73 | |||
| 74 | $periods = $backend->selectPeriods($criteria); |
||
| 75 | |||
| 76 | foreach ($periods as $period) { |
||
| 77 | // bab_debug($period->toHtml(), DBG_TRACE, 'caldav'); |
||
| 78 | $event->periods->addPeriod($period); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 160 |