| Conditions | 8 |
| Paths | 5 |
| Total Lines | 54 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 85 | function wpbo_single_activate() { |
||
| 86 | |||
| 87 | /* Add new role */ |
||
| 88 | $subscriber = get_role( 'subscriber' ); |
||
| 89 | add_role( 'betteroptin', 'BetterOptin', $subscriber->capabilities ); |
||
| 90 | |||
| 91 | /* Create database table */ |
||
| 92 | wpbo_create_table(); |
||
| 93 | wpbo_failsafe_create_table(); |
||
| 94 | |||
| 95 | /* Write database version */ |
||
| 96 | update_option( 'wpbo_db_version', WPBO_DB_VERSION ); |
||
| 97 | |||
| 98 | $defaults = get_option( 'wpbo_options', array() ); |
||
| 99 | |||
| 100 | // Register default options |
||
| 101 | if ( empty( $defaults ) ) { |
||
| 102 | |||
| 103 | // Get default options |
||
| 104 | if ( ! function_exists( 'wpbo_settings_general' ) ) { |
||
| 105 | require( WPBO_PATH . 'includes/admin/settings/settings-general.php' ); |
||
| 106 | } |
||
| 107 | |||
| 108 | $options = apply_filters( 'wpbo_plugin_settings', array() ); |
||
| 109 | |||
| 110 | foreach ( $options as $section_id => $section ) { |
||
| 111 | |||
| 112 | foreach ( $section['options'] as $option ) { |
||
| 113 | |||
| 114 | if ( ! isset( $option['id'] ) ) { |
||
| 115 | continue; |
||
| 116 | } |
||
| 117 | |||
| 118 | $value = isset( $option['default'] ) ? $option['default'] : ''; |
||
| 119 | $defaults[ $option['id'] ] = $value; |
||
| 120 | |||
| 121 | } |
||
| 122 | |||
| 123 | } |
||
| 124 | |||
| 125 | if ( ! empty( $defaults ) ) { |
||
| 126 | update_option( 'wpbo_options', serialize( $defaults ) ); |
||
| 127 | } |
||
| 128 | |||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Add an option in DB to know when the plugin has just been activated. |
||
| 133 | * |
||
| 134 | * @link http://stackoverflow.com/questions/7738953/is-there-a-way-to-determine-if-a-wordpress-plugin-is-just-installed/13927297#13927297 |
||
| 135 | */ |
||
| 136 | add_option( 'wpbo_just_activated', true ); |
||
| 137 | |||
| 138 | } |
||
| 139 | |||
| 193 | } |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.