| Conditions | 23 |
| Paths | 29 |
| Total Lines | 54 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 37 | function monsterinsights_add_capabilities( $caps, $cap, $user_id, $args ) { |
||
|
|
|||
| 38 | |||
| 39 | switch ( $cap ) { |
||
| 40 | case 'monsterinsights_view_dashboard' : |
||
| 41 | $roles = monsterinsights_get_option( 'view_reports', array() ); |
||
| 42 | |||
| 43 | $user_can_via_settings = false; |
||
| 44 | if ( ! empty( $roles ) && is_array( $roles ) ) { |
||
| 45 | foreach ( $roles as $role ) { |
||
| 46 | if ( is_string( $role ) ) { |
||
| 47 | if ( user_can( $user_id, $role ) ) { |
||
| 48 | $user_can_via_settings = true; |
||
| 49 | break; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } else if ( ! empty( $roles ) && is_string( $roles ) ) { |
||
| 54 | if ( user_can( $user_id, $roles ) ) { |
||
| 55 | $user_can_via_settings = true; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | if ( user_can( $user_id, 'manage_options' ) || $user_can_via_settings ) { |
||
| 60 | $caps = array(); |
||
| 61 | } |
||
| 62 | |||
| 63 | break; |
||
| 64 | case 'monsterinsights_save_settings' : |
||
| 65 | $roles = monsterinsights_get_option( 'save_settings', array() ); |
||
| 66 | |||
| 67 | $user_can_via_settings = false; |
||
| 68 | if ( ! empty( $roles ) && is_array( $roles ) ) { |
||
| 69 | foreach ( $roles as $role ) { |
||
| 70 | if ( is_string( $role ) ) { |
||
| 71 | if ( user_can( $user_id, $role ) ) { |
||
| 72 | $user_can_via_settings = true; |
||
| 73 | break; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } else if ( ! empty( $roles ) && is_string( $roles ) ) { |
||
| 78 | if ( user_can( $user_id, $roles ) ) { |
||
| 79 | $user_can_via_settings = true; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if ( user_can( $user_id, 'manage_options' ) || $user_can_via_settings ) { |
||
| 84 | $caps = array(); |
||
| 85 | } |
||
| 86 | |||
| 87 | break; |
||
| 88 | } |
||
| 89 | |||
| 90 | return $caps; |
||
| 91 | } |
||
| 94 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.