| Conditions | 7 |
| Paths | 16 |
| Total Lines | 51 |
| Code Lines | 29 |
| 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 namespace CalDAVClient\Facade\Utils; |
||
| 94 | public static function build(DateTimeZone $time_zone, $calendar_prod_id, $with_calendar_envelope = true){ |
||
| 95 | |||
| 96 | // get all transitions for one current year and next |
||
| 97 | list($start_range, $end_range) = self::calculateTimeRangeForTransitions($time_zone); |
||
| 98 | $transitions = $time_zone->getTransitions($start_range->getTimestamp(), $end_range->getTimestamp()); |
||
| 99 | $vTimezone = new Timezone($time_zone->getName()); |
||
| 100 | $former_offset = null; |
||
| 101 | |||
| 102 | foreach ($transitions as $i => $trans) { |
||
| 103 | $current_time_zone_rule = null; |
||
| 104 | |||
| 105 | // skip the first entry... |
||
| 106 | if ($i == 0) { |
||
| 107 | // ... but remember the offset for the next TZOFFSETFROM value |
||
| 108 | $former_offset = $trans['offset'] / 3600; |
||
| 109 | continue; |
||
| 110 | } |
||
| 111 | |||
| 112 | // daylight saving time definition |
||
| 113 | if ($trans['isdst']) { |
||
| 114 | $current_time_zone_rule = new TimezoneRule(TimezoneRule::TYPE_DAYLIGHT);; |
||
| 115 | } |
||
| 116 | // standard time definition |
||
| 117 | else { |
||
| 118 | $current_time_zone_rule = new TimezoneRule(TimezoneRule::TYPE_STANDARD);; |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($current_time_zone_rule) { |
||
| 122 | $offset = $trans['offset'] / 3600; |
||
| 123 | $dt = self::convertStartDateFromUTC2Local($trans, $former_offset); |
||
| 124 | $current_time_zone_rule->setDtStart($dt); |
||
| 125 | $current_time_zone_rule->setTzOffsetFrom(self::calculateOffsetFrom($former_offset)); |
||
| 126 | $current_time_zone_rule->setTzOffsetTo(self::calculateOffsetTo($offset)); |
||
| 127 | |||
| 128 | // add abbreviated timezone name if available |
||
| 129 | if (!empty($trans['abbr'])) { |
||
| 130 | $current_time_zone_rule->setTzName($trans['abbr']); |
||
| 131 | } |
||
| 132 | |||
| 133 | $former_offset = $offset; |
||
| 134 | $current_time_zone_rule->setRecurrenceRule(self::calculateRecurrenceRule($dt)); |
||
| 135 | $vTimezone->addComponent($current_time_zone_rule); |
||
| 136 | } |
||
| 137 | |||
| 138 | } |
||
| 139 | if($with_calendar_envelope) { |
||
| 140 | $vCalendar = new Calendar(sprintf("'-//%s//EN'", $calendar_prod_id)); |
||
| 141 | $vCalendar->setTimezone($vTimezone); |
||
| 142 | return $vCalendar; |
||
| 143 | }; |
||
| 144 | return $vTimezone; |
||
| 145 | } |
||
| 206 | } |