Conditions | 13 |
Paths | 30 |
Total Lines | 49 |
Code Lines | 27 |
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 |
||
102 | public static function get_local_timezone( $reset = FALSE ) { |
||
103 | _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
||
104 | if ( $reset ) { |
||
105 | self::$local_timezone = NULL; |
||
106 | } |
||
107 | if ( !isset(self::$local_timezone) ) { |
||
108 | $tzstring = get_option('timezone_string'); |
||
109 | |||
110 | if ( empty($tzstring) ) { |
||
111 | $gmt_offset = get_option('gmt_offset'); |
||
112 | if ( $gmt_offset == 0 ) { |
||
113 | $tzstring = 'UTC'; |
||
114 | } else { |
||
115 | $gmt_offset *= HOUR_IN_SECONDS; |
||
116 | $tzstring = timezone_name_from_abbr( '', $gmt_offset, 1 ); |
||
117 | |||
118 | // If there's no timezone string, try again with no DST. |
||
119 | if ( false === $tzstring ) { |
||
120 | $tzstring = timezone_name_from_abbr( '', $gmt_offset, 0 ); |
||
121 | } |
||
122 | |||
123 | // Try mapping to the first abbreviation we can find. |
||
124 | if ( false === $tzstring ) { |
||
125 | $is_dst = date( 'I' ); |
||
126 | foreach ( timezone_abbreviations_list() as $abbr ) { |
||
127 | foreach ( $abbr as $city ) { |
||
128 | if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) { |
||
129 | // If there's no valid timezone ID, keep looking. |
||
130 | if ( null === $city['timezone_id'] ) { |
||
131 | continue; |
||
132 | } |
||
133 | |||
134 | $tzstring = $city['timezone_id']; |
||
135 | break 2; |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | |||
141 | // If we still have no valid string, then fall back to UTC. |
||
142 | if ( false === $tzstring ) { |
||
143 | $tzstring = 'UTC'; |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | |||
148 | self::$local_timezone = new DateTimeZone($tzstring); |
||
149 | } |
||
150 | return self::$local_timezone; |
||
151 | } |
||
153 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.