| Conditions | 7 |
| Paths | 64 |
| Total Lines | 112 |
| Code Lines | 92 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 237 | public function get_menu_items(){ |
||
| 238 | $items = array(); |
||
| 239 | |||
| 240 | $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' ); |
||
| 241 | if($wpinv_history_page_id > 0){ |
||
| 242 | $item = new stdClass(); |
||
| 243 | $item->object_id = $wpinv_history_page_id; |
||
| 244 | $item->db_id = 0; |
||
| 245 | $item->object = 'page'; |
||
| 246 | $item->menu_item_parent = 0; |
||
| 247 | $item->type = 'post_type'; |
||
| 248 | $item->title = __('Invoice History Page','invoicing'); |
||
| 249 | $item->url = get_permalink( $wpinv_history_page_id ); |
||
| 250 | $item->target = ''; |
||
| 251 | $item->attr_title = ''; |
||
| 252 | $item->classes = array('wpinv-menu-item'); |
||
| 253 | $item->xfn = ''; |
||
| 254 | |||
| 255 | $items['pages'][] = $item; |
||
| 256 | } |
||
| 257 | |||
| 258 | $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' ); |
||
| 259 | if($wpinv_sub_history_page_id > 0){ |
||
| 260 | $item = new stdClass(); |
||
| 261 | $item->object_id = $wpinv_sub_history_page_id; |
||
| 262 | $item->db_id = 0; |
||
| 263 | $item->object = 'page'; |
||
| 264 | $item->menu_item_parent = 0; |
||
| 265 | $item->type = 'post_type'; |
||
| 266 | $item->title = __('Invoice Subscriptions Page','invoicing'); |
||
| 267 | $item->url = get_permalink( $wpinv_sub_history_page_id ); |
||
| 268 | $item->target = ''; |
||
| 269 | $item->attr_title = ''; |
||
| 270 | $item->classes = array('wpinv-menu-item'); |
||
| 271 | $item->xfn = ''; |
||
| 272 | |||
| 273 | $items['pages'][] = $item; |
||
| 274 | } |
||
| 275 | |||
| 276 | $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' ); |
||
| 277 | if($wpinv_checkout_page_id > 0){ |
||
| 278 | $item = new stdClass(); |
||
| 279 | $item->object_id = $wpinv_checkout_page_id; |
||
| 280 | $item->db_id = 0; |
||
| 281 | $item->object = 'page'; |
||
| 282 | $item->menu_item_parent = 0; |
||
| 283 | $item->type = 'post_type'; |
||
| 284 | $item->title = __('Checkout Page','invoicing'); |
||
| 285 | $item->url = get_permalink( $wpinv_checkout_page_id ); |
||
| 286 | $item->target = ''; |
||
| 287 | $item->attr_title = ''; |
||
| 288 | $item->classes = array('wpinv-menu-item'); |
||
| 289 | $item->xfn = ''; |
||
| 290 | |||
| 291 | $items['pages'][] = $item; |
||
| 292 | } |
||
| 293 | |||
| 294 | $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' ); |
||
| 295 | if($wpinv_tandc_page_id > 0){ |
||
| 296 | $item = new stdClass(); |
||
| 297 | $item->object_id = $wpinv_tandc_page_id; |
||
| 298 | $item->db_id = 0; |
||
| 299 | $item->object = 'page'; |
||
| 300 | $item->menu_item_parent = 0; |
||
| 301 | $item->type = 'post_type'; |
||
| 302 | $item->title = __('Terms & Conditions','invoicing'); |
||
| 303 | $item->url = get_permalink( $wpinv_tandc_page_id ); |
||
| 304 | $item->target = ''; |
||
| 305 | $item->attr_title = ''; |
||
| 306 | $item->classes = array('wpinv-menu-item'); |
||
| 307 | $item->xfn = ''; |
||
| 308 | |||
| 309 | $items['pages'][] = $item; |
||
| 310 | } |
||
| 311 | |||
| 312 | $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' ); |
||
| 313 | if($wpinv_success_page_id > 0){ |
||
| 314 | $item = new stdClass(); |
||
| 315 | $item->object_id = $wpinv_success_page_id; |
||
| 316 | $item->db_id = 0; |
||
| 317 | $item->object = 'page'; |
||
| 318 | $item->menu_item_parent = 0; |
||
| 319 | $item->type = 'post_type'; |
||
| 320 | $item->title = __('Success Page','invoicing'); |
||
| 321 | $item->url = get_permalink( $wpinv_success_page_id ); |
||
| 322 | $item->target = ''; |
||
| 323 | $item->attr_title = ''; |
||
| 324 | $item->classes = array('wpinv-menu-item'); |
||
| 325 | $item->xfn = ''; |
||
| 326 | |||
| 327 | $items['pages'][] = $item; |
||
| 328 | } |
||
| 329 | |||
| 330 | $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' ); |
||
| 331 | if($wpinv_failure_page_id > 0){ |
||
| 332 | $item = new stdClass(); |
||
| 333 | $item->object_id = $wpinv_failure_page_id; |
||
| 334 | $item->db_id = 0; |
||
| 335 | $item->object = 'page'; |
||
| 336 | $item->menu_item_parent = 0; |
||
| 337 | $item->type = 'post_type'; |
||
| 338 | $item->title = __('Failed Transaction Page','invoicing'); |
||
| 339 | $item->url = get_permalink( $wpinv_failure_page_id ); |
||
| 340 | $item->target = ''; |
||
| 341 | $item->attr_title = ''; |
||
| 342 | $item->classes = array('wpinv-menu-item'); |
||
| 343 | $item->xfn = ''; |
||
| 344 | |||
| 345 | $items['pages'][] = $item; |
||
| 346 | } |
||
| 347 | |||
| 348 | return apply_filters( 'wpinv_menu_items', $items ); |
||
| 349 | } |
||
| 353 | return new WPInv_Admin_Menus(); |