Conditions | 7 |
Paths | 64 |
Total Lines | 113 |
Lines | 96 |
Ratio | 84.96 % |
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 |
||
174 | public function get_menu_items(){ |
||
175 | $items = array(); |
||
176 | |||
177 | $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' ); |
||
178 | View Code Duplication | if($wpinv_history_page_id > 0){ |
|
179 | $item = new stdClass(); |
||
180 | $item->object_id = $wpinv_history_page_id; |
||
181 | $item->db_id = 0; |
||
182 | $item->object = 'page'; |
||
183 | $item->menu_item_parent = 0; |
||
184 | $item->type = 'post_type'; |
||
185 | $item->title = __('Invoice History Page','invoicing'); |
||
186 | $item->url = get_permalink( $wpinv_history_page_id ); |
||
187 | $item->target = ''; |
||
188 | $item->attr_title = ''; |
||
189 | $item->classes = array('wpinv-menu-item'); |
||
190 | $item->xfn = ''; |
||
191 | |||
192 | $items['pages'][] = $item; |
||
193 | } |
||
194 | |||
195 | $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' ); |
||
196 | View Code Duplication | if($wpinv_sub_history_page_id > 0){ |
|
197 | $item = new stdClass(); |
||
198 | $item->object_id = $wpinv_sub_history_page_id; |
||
199 | $item->db_id = 0; |
||
200 | $item->object = 'page'; |
||
201 | $item->menu_item_parent = 0; |
||
202 | $item->type = 'post_type'; |
||
203 | $item->title = __('Invoice Subscriptions Page','invoicing'); |
||
204 | $item->url = get_permalink( $wpinv_sub_history_page_id ); |
||
205 | $item->target = ''; |
||
206 | $item->attr_title = ''; |
||
207 | $item->classes = array('wpinv-menu-item'); |
||
208 | $item->xfn = ''; |
||
209 | |||
210 | $items['pages'][] = $item; |
||
211 | } |
||
212 | |||
213 | $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' ); |
||
214 | View Code Duplication | if($wpinv_checkout_page_id > 0){ |
|
215 | $item = new stdClass(); |
||
216 | $item->object_id = $wpinv_checkout_page_id; |
||
217 | $item->db_id = 0; |
||
218 | $item->object = 'page'; |
||
219 | $item->menu_item_parent = 0; |
||
220 | $item->type = 'post_type'; |
||
221 | $item->title = __('Checkout Page','invoicing'); |
||
222 | $item->url = get_permalink( $wpinv_checkout_page_id ); |
||
223 | $item->target = ''; |
||
224 | $item->attr_title = ''; |
||
225 | $item->classes = array('wpinv-menu-item'); |
||
226 | $item->xfn = ''; |
||
227 | |||
228 | $items['pages'][] = $item; |
||
229 | } |
||
230 | |||
231 | $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' ); |
||
232 | View Code Duplication | if($wpinv_tandc_page_id > 0){ |
|
233 | $item = new stdClass(); |
||
234 | $item->object_id = $wpinv_tandc_page_id; |
||
235 | $item->db_id = 0; |
||
236 | $item->object = 'page'; |
||
237 | $item->menu_item_parent = 0; |
||
238 | $item->type = 'post_type'; |
||
239 | $item->title = __('Terms & Conditions','invoicing'); |
||
240 | $item->url = get_permalink( $wpinv_tandc_page_id ); |
||
241 | $item->target = ''; |
||
242 | $item->attr_title = ''; |
||
243 | $item->classes = array('wpinv-menu-item'); |
||
244 | $item->xfn = ''; |
||
245 | |||
246 | $items['pages'][] = $item; |
||
247 | } |
||
248 | |||
249 | $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' ); |
||
250 | View Code Duplication | if($wpinv_success_page_id > 0){ |
|
251 | $item = new stdClass(); |
||
252 | $item->object_id = $wpinv_success_page_id; |
||
253 | $item->db_id = 0; |
||
254 | $item->object = 'page'; |
||
255 | $item->menu_item_parent = 0; |
||
256 | $item->type = 'post_type'; |
||
257 | $item->title = __('Success Page','invoicing'); |
||
258 | $item->url = get_permalink( $wpinv_success_page_id ); |
||
259 | $item->target = ''; |
||
260 | $item->attr_title = ''; |
||
261 | $item->classes = array('wpinv-menu-item'); |
||
262 | $item->xfn = ''; |
||
263 | |||
264 | $items['pages'][] = $item; |
||
265 | } |
||
266 | |||
267 | $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' ); |
||
268 | View Code Duplication | if($wpinv_failure_page_id > 0){ |
|
269 | $item = new stdClass(); |
||
270 | $item->object_id = $wpinv_failure_page_id; |
||
271 | $item->db_id = 0; |
||
272 | $item->object = 'page'; |
||
273 | $item->menu_item_parent = 0; |
||
274 | $item->type = 'post_type'; |
||
275 | $item->title = __('Failed Transaction Page','invoicing'); |
||
276 | $item->url = get_permalink( $wpinv_failure_page_id ); |
||
277 | $item->target = ''; |
||
278 | $item->attr_title = ''; |
||
279 | $item->classes = array('wpinv-menu-item'); |
||
280 | $item->xfn = ''; |
||
281 | |||
282 | $items['pages'][] = $item; |
||
283 | } |
||
284 | |||
285 | return apply_filters( 'wpinv_menu_items', $items ); |
||
286 | } |
||
287 | |||
290 | return new WPInv_Admin_Menus(); |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.