| 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 | ||
| 195 |     public function get_menu_items(){ | ||
| 196 | $items = array(); | ||
| 197 | |||
| 198 | $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' ); | ||
| 199 | View Code Duplication |         if($wpinv_history_page_id > 0){ | |
| 200 | $item = new stdClass(); | ||
| 201 | $item->object_id = $wpinv_history_page_id; | ||
| 202 | $item->db_id = 0; | ||
| 203 | $item->object = 'page'; | ||
| 204 | $item->menu_item_parent = 0; | ||
| 205 | $item->type = 'post_type'; | ||
| 206 |             $item->title = __('Invoice History Page','invoicing'); | ||
| 207 | $item->url = get_permalink( $wpinv_history_page_id ); | ||
| 208 | $item->target = ''; | ||
| 209 | $item->attr_title = ''; | ||
| 210 |             $item->classes = array('wpinv-menu-item'); | ||
| 211 | $item->xfn = ''; | ||
| 212 | |||
| 213 | $items['pages'][] = $item; | ||
| 214 | } | ||
| 215 | |||
| 216 | $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' ); | ||
| 217 | View Code Duplication |         if($wpinv_sub_history_page_id > 0){ | |
| 218 | $item = new stdClass(); | ||
| 219 | $item->object_id = $wpinv_sub_history_page_id; | ||
| 220 | $item->db_id = 0; | ||
| 221 | $item->object = 'page'; | ||
| 222 | $item->menu_item_parent = 0; | ||
| 223 | $item->type = 'post_type'; | ||
| 224 |             $item->title = __('Invoice Subscriptions Page','invoicing'); | ||
| 225 | $item->url = get_permalink( $wpinv_sub_history_page_id ); | ||
| 226 | $item->target = ''; | ||
| 227 | $item->attr_title = ''; | ||
| 228 |             $item->classes = array('wpinv-menu-item'); | ||
| 229 | $item->xfn = ''; | ||
| 230 | |||
| 231 | $items['pages'][] = $item; | ||
| 232 | } | ||
| 233 | |||
| 234 | $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' ); | ||
| 235 | View Code Duplication |         if($wpinv_checkout_page_id > 0){ | |
| 236 | $item = new stdClass(); | ||
| 237 | $item->object_id = $wpinv_checkout_page_id; | ||
| 238 | $item->db_id = 0; | ||
| 239 | $item->object = 'page'; | ||
| 240 | $item->menu_item_parent = 0; | ||
| 241 | $item->type = 'post_type'; | ||
| 242 |             $item->title = __('Checkout Page','invoicing'); | ||
| 243 | $item->url = get_permalink( $wpinv_checkout_page_id ); | ||
| 244 | $item->target = ''; | ||
| 245 | $item->attr_title = ''; | ||
| 246 |             $item->classes = array('wpinv-menu-item'); | ||
| 247 | $item->xfn = ''; | ||
| 248 | |||
| 249 | $items['pages'][] = $item; | ||
| 250 | } | ||
| 251 | |||
| 252 | $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' ); | ||
| 253 | View Code Duplication |         if($wpinv_tandc_page_id > 0){ | |
| 254 | $item = new stdClass(); | ||
| 255 | $item->object_id = $wpinv_tandc_page_id; | ||
| 256 | $item->db_id = 0; | ||
| 257 | $item->object = 'page'; | ||
| 258 | $item->menu_item_parent = 0; | ||
| 259 | $item->type = 'post_type'; | ||
| 260 |             $item->title = __('Terms & Conditions','invoicing'); | ||
| 261 | $item->url = get_permalink( $wpinv_tandc_page_id ); | ||
| 262 | $item->target = ''; | ||
| 263 | $item->attr_title = ''; | ||
| 264 |             $item->classes = array('wpinv-menu-item'); | ||
| 265 | $item->xfn = ''; | ||
| 266 | |||
| 267 | $items['pages'][] = $item; | ||
| 268 | } | ||
| 269 | |||
| 270 | $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' ); | ||
| 271 | View Code Duplication |         if($wpinv_success_page_id > 0){ | |
| 272 | $item = new stdClass(); | ||
| 273 | $item->object_id = $wpinv_success_page_id; | ||
| 274 | $item->db_id = 0; | ||
| 275 | $item->object = 'page'; | ||
| 276 | $item->menu_item_parent = 0; | ||
| 277 | $item->type = 'post_type'; | ||
| 278 |             $item->title = __('Success Page','invoicing'); | ||
| 279 | $item->url = get_permalink( $wpinv_success_page_id ); | ||
| 280 | $item->target = ''; | ||
| 281 | $item->attr_title = ''; | ||
| 282 |             $item->classes = array('wpinv-menu-item'); | ||
| 283 | $item->xfn = ''; | ||
| 284 | |||
| 285 | $items['pages'][] = $item; | ||
| 286 | } | ||
| 287 | |||
| 288 | $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' ); | ||
| 289 | View Code Duplication |         if($wpinv_failure_page_id > 0){ | |
| 290 | $item = new stdClass(); | ||
| 291 | $item->object_id = $wpinv_failure_page_id; | ||
| 292 | $item->db_id = 0; | ||
| 293 | $item->object = 'page'; | ||
| 294 | $item->menu_item_parent = 0; | ||
| 295 | $item->type = 'post_type'; | ||
| 296 |             $item->title = __('Failed Transaction Page','invoicing'); | ||
| 297 | $item->url = get_permalink( $wpinv_failure_page_id ); | ||
| 298 | $item->target = ''; | ||
| 299 | $item->attr_title = ''; | ||
| 300 |             $item->classes = array('wpinv-menu-item'); | ||
| 301 | $item->xfn = ''; | ||
| 302 | |||
| 303 | $items['pages'][] = $item; | ||
| 304 | } | ||
| 305 | |||
| 306 | return apply_filters( 'wpinv_menu_items', $items ); | ||
| 307 | } | ||
| 308 | |||
| 311 | 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.