| Conditions | 11 |
| Paths | 136 |
| Total Lines | 113 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 108 | function get_modules() { |
||
| 109 | include_once JETPACK__PLUGIN_DIR . 'modules/module-info.php'; |
||
| 110 | $available_modules = Jetpack::get_available_modules(); |
||
| 111 | $active_modules = Jetpack::get_active_modules(); |
||
| 112 | $modules = array(); |
||
| 113 | $jetpack_active = Jetpack::is_active() || ( new Status() )->is_offline_mode(); |
||
| 114 | $overrides = Jetpack_Modules_Overrides::instance(); |
||
| 115 | foreach ( $available_modules as $module ) { |
||
| 116 | if ( $module_array = Jetpack::get_module( $module ) ) { |
||
| 117 | /** |
||
| 118 | * Filters each module's short description. |
||
| 119 | * |
||
| 120 | * @since 3.0.0 |
||
| 121 | * |
||
| 122 | * @param string $module_array['description'] Module description. |
||
| 123 | * @param string $module Module slug. |
||
| 124 | */ |
||
| 125 | $short_desc = apply_filters( 'jetpack_short_module_description', $module_array['description'], $module ); |
||
| 126 | // Fix: correct multibyte strings truncate with checking for mbstring extension |
||
| 127 | $short_desc_trunc = ( function_exists( 'mb_strlen' ) ) |
||
| 128 | ? ( ( mb_strlen( $short_desc ) > 143 ) |
||
| 129 | ? mb_substr( $short_desc, 0, 140 ) . '...' |
||
| 130 | : $short_desc ) |
||
| 131 | : ( ( strlen( $short_desc ) > 143 ) |
||
| 132 | ? substr( $short_desc, 0, 140 ) . '...' |
||
| 133 | : $short_desc ); |
||
| 134 | |||
| 135 | $module_array['module'] = $module; |
||
| 136 | $module_array['activated'] = ( $jetpack_active ? in_array( $module, $active_modules ) : false ); |
||
| 137 | $module_array['deactivate_nonce'] = wp_create_nonce( 'jetpack_deactivate-' . $module ); |
||
| 138 | $module_array['activate_nonce'] = wp_create_nonce( 'jetpack_activate-' . $module ); |
||
| 139 | $module_array['available'] = self::is_module_available( $module_array ); |
||
| 140 | $module_array['short_description'] = $short_desc_trunc; |
||
| 141 | $module_array['configure_url'] = Jetpack::module_configuration_url( $module ); |
||
| 142 | $module_array['override'] = $overrides->get_module_override( $module ); |
||
| 143 | |||
| 144 | ob_start(); |
||
| 145 | /** |
||
| 146 | * Allow the display of a "Learn More" button. |
||
| 147 | * The dynamic part of the action, $module, is the module slug. |
||
| 148 | * |
||
| 149 | * @since 3.0.0 |
||
| 150 | */ |
||
| 151 | do_action( 'jetpack_learn_more_button_' . $module ); |
||
| 152 | $module_array['learn_more_button'] = ob_get_clean(); |
||
| 153 | |||
| 154 | ob_start(); |
||
| 155 | /** |
||
| 156 | * Allow the display of information text when Jetpack is connected to WordPress.com. |
||
| 157 | * The dynamic part of the action, $module, is the module slug. |
||
| 158 | * |
||
| 159 | * @since 3.0.0 |
||
| 160 | */ |
||
| 161 | do_action( 'jetpack_module_more_info_' . $module ); |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Filter the long description of a module. |
||
| 165 | * |
||
| 166 | * @since 3.5.0 |
||
| 167 | * |
||
| 168 | * @param string ob_get_clean() The module long description. |
||
| 169 | * @param string $module The module name. |
||
| 170 | */ |
||
| 171 | $module_array['long_description'] = apply_filters( 'jetpack_long_module_description', ob_get_clean(), $module ); |
||
| 172 | |||
| 173 | ob_start(); |
||
| 174 | /** |
||
| 175 | * Filter the search terms for a module |
||
| 176 | * |
||
| 177 | * Search terms are typically added to the module headers, under "Additional Search Queries". |
||
| 178 | * |
||
| 179 | * Use syntax: |
||
| 180 | * function jetpack_$module_search_terms( $terms ) { |
||
| 181 | * $terms = _x( 'term 1, term 2', 'search terms', 'jetpack' ); |
||
| 182 | * return $terms; |
||
| 183 | * } |
||
| 184 | * add_filter( 'jetpack_search_terms_$module', 'jetpack_$module_search_terms' ); |
||
| 185 | * |
||
| 186 | * @since 3.5.0 |
||
| 187 | * |
||
| 188 | * @param string The search terms (comma separated). |
||
| 189 | */ |
||
| 190 | echo apply_filters( 'jetpack_search_terms_' . $module, $module_array['additional_search_queries'] ); |
||
| 191 | $module_array['search_terms'] = ob_get_clean(); |
||
| 192 | |||
| 193 | $module_array['configurable'] = false; |
||
| 194 | if ( |
||
| 195 | current_user_can( 'manage_options' ) && |
||
| 196 | /** |
||
| 197 | * Allow the display of a configuration link in the Jetpack Settings screen. |
||
| 198 | * |
||
| 199 | * @since 3.0.0 |
||
| 200 | * |
||
| 201 | * @param string $module Module name. |
||
| 202 | * @param bool false Should the Configure module link be displayed? Default to false. |
||
| 203 | */ |
||
| 204 | apply_filters( 'jetpack_module_configurable_' . $module, false ) |
||
| 205 | ) { |
||
| 206 | $module_array['configurable'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $module_array['configure_url'] ), __( 'Configure', 'jetpack' ) ); |
||
| 207 | } |
||
| 208 | |||
| 209 | $modules[ $module ] = $module_array; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | uasort( $modules, array( 'Jetpack', 'sort_modules' ) ); |
||
| 214 | |||
| 215 | if ( ! Jetpack::is_active() ) { |
||
| 216 | uasort( $modules, array( __CLASS__, 'sort_requires_connection_last' ) ); |
||
| 217 | } |
||
| 218 | |||
| 219 | return $modules; |
||
| 220 | } |
||
| 221 | |||
| 334 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: