Conditions | 16 |
Paths | 672 |
Total Lines | 93 |
Code Lines | 68 |
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 |
||
122 | public function timezoneSelectInput($timezone_string = '') |
||
123 | { |
||
124 | // get WP date time format |
||
125 | $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
||
126 | // if passed a value, then use that, else get WP option |
||
127 | $timezone_string = ! empty($timezone_string) ? $timezone_string : (string)get_option('timezone_string'); |
||
128 | // check if the timezone is valid but don't throw any errors if it isn't |
||
129 | $timezone_string = $this->validateTimezone($timezone_string, false) |
||
130 | ? $timezone_string |
||
131 | : ''; |
||
132 | $gmt_offset = get_option('gmt_offset'); |
||
133 | $check_zone_info = true; |
||
134 | if (empty($timezone_string)) { |
||
135 | // Create a UTC+- zone if no timezone string exists |
||
136 | $timezone_string = 'UTC'; |
||
137 | $check_zone_info = false; |
||
138 | if ($gmt_offset > 0) { |
||
139 | $timezone_string = 'UTC+' . $gmt_offset; |
||
140 | } elseif ($gmt_offset < 0) { |
||
141 | $timezone_string = 'UTC' . $gmt_offset; |
||
142 | } |
||
143 | } |
||
144 | ?> |
||
145 | <p> |
||
146 | <label for="timezone_string"><?php _e('timezone'); ?></label> |
||
147 | <select id="timezone_string" name="timezone_string"> |
||
148 | <?php echo wp_timezone_choice($timezone_string); ?> |
||
149 | </select> |
||
150 | <br/> |
||
151 | <span class="description"><?php _e('Choose a city in the same timezone as the event.'); ?></span> |
||
152 | </p> |
||
153 | |||
154 | <p> |
||
155 | <span><?php |
||
156 | printf( |
||
157 | __('%1$sUTC%2$s time is %3$s'), |
||
158 | '<abbr title="Coordinated Universal Time">', |
||
159 | '</abbr>', |
||
160 | '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
||
161 | ); |
||
162 | ?></span> |
||
163 | <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
||
164 | <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
||
165 | <?php endif; ?> |
||
166 | |||
167 | <?php if ($check_zone_info && $timezone_string) : ?> |
||
168 | <br/> |
||
169 | <span> |
||
170 | <?php |
||
171 | // Set TZ so localtime works. |
||
172 | date_default_timezone_set($timezone_string); |
||
173 | $now = localtime(time(), true); |
||
174 | if ($now['tm_isdst']) { |
||
175 | _e('This timezone is currently in daylight saving time.'); |
||
176 | } else { |
||
177 | _e('This timezone is currently in standard time.'); |
||
178 | } |
||
179 | ?> |
||
180 | <br/> |
||
181 | <?php |
||
182 | if (function_exists('timezone_transitions_get')) { |
||
183 | $found = false; |
||
184 | $date_time_zone_selected = new DateTimeZone($timezone_string); |
||
185 | $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
||
186 | $right_now = time(); |
||
187 | $tr['isdst'] = false; |
||
188 | foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
||
189 | if ($tr['ts'] > $right_now) { |
||
190 | $found = true; |
||
191 | break; |
||
192 | } |
||
193 | } |
||
194 | if ($found) { |
||
195 | $message = $tr['isdst'] |
||
196 | ? __(' Daylight saving time begins on: %s.') |
||
197 | : __(' Standard time begins on: %s.'); |
||
198 | // Add the difference between the current offset and the new offset to ts to get the correct |
||
199 | // transition time from date_i18n(). |
||
200 | printf( |
||
201 | $message, |
||
202 | '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >' |
||
203 | ); |
||
204 | } else { |
||
205 | _e('This timezone does not observe daylight saving time.'); |
||
206 | } |
||
207 | } |
||
208 | // Set back to UTC. |
||
209 | date_default_timezone_set('UTC'); |
||
210 | ?> |
||
211 | </span></p> |
||
212 | <?php |
||
213 | endif; |
||
214 | } |
||
215 | |||
300 |