Conditions | 8 |
Paths | 48 |
Total Lines | 109 |
Code Lines | 77 |
Lines | 0 |
Ratio | 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 |
||
110 | public function init() { |
||
111 | // The Weekdays |
||
112 | $this->weekday[0] = /* translators: weekday */ __('Sunday'); |
||
113 | $this->weekday[1] = /* translators: weekday */ __('Monday'); |
||
114 | $this->weekday[2] = /* translators: weekday */ __('Tuesday'); |
||
115 | $this->weekday[3] = /* translators: weekday */ __('Wednesday'); |
||
116 | $this->weekday[4] = /* translators: weekday */ __('Thursday'); |
||
117 | $this->weekday[5] = /* translators: weekday */ __('Friday'); |
||
118 | $this->weekday[6] = /* translators: weekday */ __('Saturday'); |
||
119 | |||
120 | // The first letter of each day. |
||
121 | $this->weekday_initial[ __( 'Sunday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'S', 'Sunday initial' ); |
||
122 | $this->weekday_initial[ __( 'Monday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'M', 'Monday initial' ); |
||
123 | $this->weekday_initial[ __( 'Tuesday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'T', 'Tuesday initial' ); |
||
124 | $this->weekday_initial[ __( 'Wednesday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'W', 'Wednesday initial' ); |
||
125 | $this->weekday_initial[ __( 'Thursday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'T', 'Thursday initial' ); |
||
126 | $this->weekday_initial[ __( 'Friday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'F', 'Friday initial' ); |
||
127 | $this->weekday_initial[ __( 'Saturday' ) ] = /* translators: one-letter abbreviation of the weekday */ _x( 'S', 'Saturday initial' ); |
||
128 | |||
129 | // Abbreviations for each day. |
||
130 | $this->weekday_abbrev[__('Sunday')] = /* translators: three-letter abbreviation of the weekday */ __('Sun'); |
||
131 | $this->weekday_abbrev[__('Monday')] = /* translators: three-letter abbreviation of the weekday */ __('Mon'); |
||
132 | $this->weekday_abbrev[__('Tuesday')] = /* translators: three-letter abbreviation of the weekday */ __('Tue'); |
||
133 | $this->weekday_abbrev[__('Wednesday')] = /* translators: three-letter abbreviation of the weekday */ __('Wed'); |
||
134 | $this->weekday_abbrev[__('Thursday')] = /* translators: three-letter abbreviation of the weekday */ __('Thu'); |
||
135 | $this->weekday_abbrev[__('Friday')] = /* translators: three-letter abbreviation of the weekday */ __('Fri'); |
||
136 | $this->weekday_abbrev[__('Saturday')] = /* translators: three-letter abbreviation of the weekday */ __('Sat'); |
||
137 | |||
138 | // The Months |
||
139 | $this->month['01'] = /* translators: month name */ __( 'January' ); |
||
140 | $this->month['02'] = /* translators: month name */ __( 'February' ); |
||
141 | $this->month['03'] = /* translators: month name */ __( 'March' ); |
||
142 | $this->month['04'] = /* translators: month name */ __( 'April' ); |
||
143 | $this->month['05'] = /* translators: month name */ __( 'May' ); |
||
144 | $this->month['06'] = /* translators: month name */ __( 'June' ); |
||
145 | $this->month['07'] = /* translators: month name */ __( 'July' ); |
||
146 | $this->month['08'] = /* translators: month name */ __( 'August' ); |
||
147 | $this->month['09'] = /* translators: month name */ __( 'September' ); |
||
148 | $this->month['10'] = /* translators: month name */ __( 'October' ); |
||
149 | $this->month['11'] = /* translators: month name */ __( 'November' ); |
||
150 | $this->month['12'] = /* translators: month name */ __( 'December' ); |
||
151 | |||
152 | // The Months, genitive |
||
153 | $this->month_genitive['01'] = /* translators: month name, genitive */ _x( 'January', 'genitive' ); |
||
|
|||
154 | $this->month_genitive['02'] = /* translators: month name, genitive */ _x( 'February', 'genitive' ); |
||
155 | $this->month_genitive['03'] = /* translators: month name, genitive */ _x( 'March', 'genitive' ); |
||
156 | $this->month_genitive['04'] = /* translators: month name, genitive */ _x( 'April', 'genitive' ); |
||
157 | $this->month_genitive['05'] = /* translators: month name, genitive */ _x( 'May', 'genitive' ); |
||
158 | $this->month_genitive['06'] = /* translators: month name, genitive */ _x( 'June', 'genitive' ); |
||
159 | $this->month_genitive['07'] = /* translators: month name, genitive */ _x( 'July', 'genitive' ); |
||
160 | $this->month_genitive['08'] = /* translators: month name, genitive */ _x( 'August', 'genitive' ); |
||
161 | $this->month_genitive['09'] = /* translators: month name, genitive */ _x( 'September', 'genitive' ); |
||
162 | $this->month_genitive['10'] = /* translators: month name, genitive */ _x( 'October', 'genitive' ); |
||
163 | $this->month_genitive['11'] = /* translators: month name, genitive */ _x( 'November', 'genitive' ); |
||
164 | $this->month_genitive['12'] = /* translators: month name, genitive */ _x( 'December', 'genitive' ); |
||
165 | |||
166 | // Abbreviations for each month. |
||
167 | $this->month_abbrev[ __( 'January' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Jan', 'January abbreviation' ); |
||
168 | $this->month_abbrev[ __( 'February' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Feb', 'February abbreviation' ); |
||
169 | $this->month_abbrev[ __( 'March' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Mar', 'March abbreviation' ); |
||
170 | $this->month_abbrev[ __( 'April' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Apr', 'April abbreviation' ); |
||
171 | $this->month_abbrev[ __( 'May' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'May', 'May abbreviation' ); |
||
172 | $this->month_abbrev[ __( 'June' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Jun', 'June abbreviation' ); |
||
173 | $this->month_abbrev[ __( 'July' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Jul', 'July abbreviation' ); |
||
174 | $this->month_abbrev[ __( 'August' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Aug', 'August abbreviation' ); |
||
175 | $this->month_abbrev[ __( 'September' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Sep', 'September abbreviation' ); |
||
176 | $this->month_abbrev[ __( 'October' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Oct', 'October abbreviation' ); |
||
177 | $this->month_abbrev[ __( 'November' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Nov', 'November abbreviation' ); |
||
178 | $this->month_abbrev[ __( 'December' ) ] = /* translators: three-letter abbreviation of the month */ _x( 'Dec', 'December abbreviation' ); |
||
179 | |||
180 | // The Meridiems |
||
181 | $this->meridiem['am'] = __('am'); |
||
182 | $this->meridiem['pm'] = __('pm'); |
||
183 | $this->meridiem['AM'] = __('AM'); |
||
184 | $this->meridiem['PM'] = __('PM'); |
||
185 | |||
186 | // Numbers formatting |
||
187 | // See http://php.net/number_format |
||
188 | |||
189 | /* translators: $thousands_sep argument for http://php.net/number_format, default is , */ |
||
190 | $thousands_sep = __( 'number_format_thousands_sep' ); |
||
191 | |||
192 | if ( version_compare( PHP_VERSION, '5.4', '>=' ) ) { |
||
193 | // Replace space with a non-breaking space to avoid wrapping. |
||
194 | $thousands_sep = str_replace( ' ', ' ', $thousands_sep ); |
||
195 | } else { |
||
196 | // PHP < 5.4.0 does not support multiple bytes in thousands separator. |
||
197 | $thousands_sep = str_replace( array( ' ', ' ' ), ' ', $thousands_sep ); |
||
198 | } |
||
199 | |||
200 | $this->number_format['thousands_sep'] = ( 'number_format_thousands_sep' === $thousands_sep ) ? ',' : $thousands_sep; |
||
201 | |||
202 | /* translators: $dec_point argument for http://php.net/number_format, default is . */ |
||
203 | $decimal_point = __( 'number_format_decimal_point' ); |
||
204 | |||
205 | $this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point; |
||
206 | |||
207 | // Set text direction. |
||
208 | if ( isset( $GLOBALS['text_direction'] ) ) |
||
209 | $this->text_direction = $GLOBALS['text_direction']; |
||
210 | /* translators: 'rtl' or 'ltr'. This sets the text direction for WordPress. */ |
||
211 | elseif ( 'rtl' == _x( 'ltr', 'text direction' ) ) |
||
212 | $this->text_direction = 'rtl'; |
||
213 | |||
214 | if ( 'rtl' === $this->text_direction && strpos( $GLOBALS['wp_version'], '-src' ) ) { |
||
215 | $this->text_direction = 'ltr'; |
||
216 | add_action( 'all_admin_notices', array( $this, 'rtl_src_admin_notice' ) ); |
||
217 | } |
||
218 | } |
||
219 | |||
408 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: