| Conditions | 11 |
| Paths | 136 |
| Total Lines | 111 |
| Code Lines | 42 |
| 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 |
||
| 68 | function get_modules() { |
||
| 69 | include_once( JETPACK__PLUGIN_DIR . 'modules/module-info.php' ); |
||
| 70 | $available_modules = $this->jetpack->get_available_modules(); |
||
| 71 | $active_modules = $this->jetpack->get_active_modules(); |
||
| 72 | $modules = array(); |
||
| 73 | $jetpack_active = Jetpack::is_active() || Jetpack::is_development_mode(); |
||
| 74 | foreach ( $available_modules as $module ) { |
||
| 75 | if ( $module_array = $this->jetpack->get_module( $module ) ) { |
||
| 76 | /** |
||
| 77 | * Filters each module's short description. |
||
| 78 | * |
||
| 79 | * @since 3.0.0 |
||
| 80 | * |
||
| 81 | * @param string $module_array['description'] Module description. |
||
| 82 | * @param string $module Module slug. |
||
| 83 | */ |
||
| 84 | $short_desc = apply_filters( 'jetpack_short_module_description', $module_array['description'], $module ); |
||
| 85 | // Fix: correct multibyte strings truncate with checking for mbstring extension |
||
| 86 | $short_desc_trunc = ( function_exists( 'mb_strlen' ) ) |
||
| 87 | ? ( ( mb_strlen( $short_desc ) > 143 ) |
||
| 88 | ? mb_substr( $short_desc, 0, 140 ) . '...' |
||
| 89 | : $short_desc ) |
||
| 90 | : ( ( strlen( $short_desc ) > 143 ) |
||
| 91 | ? substr( $short_desc, 0, 140 ) . '...' |
||
| 92 | : $short_desc ); |
||
| 93 | |||
| 94 | $module_array['module'] = $module; |
||
| 95 | $module_array['activated'] = ( $jetpack_active ? in_array( $module, $active_modules ) : false ); |
||
| 96 | $module_array['deactivate_nonce'] = wp_create_nonce( 'jetpack_deactivate-' . $module ); |
||
| 97 | $module_array['activate_nonce'] = wp_create_nonce( 'jetpack_activate-' . $module ); |
||
| 98 | $module_array['available'] = self::is_module_available( $module_array ); |
||
| 99 | $module_array['short_description'] = $short_desc_trunc; |
||
| 100 | $module_array['configure_url'] = Jetpack::module_configuration_url( $module ); |
||
| 101 | |||
| 102 | ob_start(); |
||
| 103 | /** |
||
| 104 | * Allow the display of a "Learn More" button. |
||
| 105 | * The dynamic part of the action, $module, is the module slug. |
||
| 106 | * |
||
| 107 | * @since 3.0.0 |
||
| 108 | */ |
||
| 109 | do_action( 'jetpack_learn_more_button_' . $module ); |
||
| 110 | $module_array['learn_more_button'] = ob_get_clean(); |
||
| 111 | |||
| 112 | ob_start(); |
||
| 113 | /** |
||
| 114 | * Allow the display of information text when Jetpack is connected to WordPress.com. |
||
| 115 | * The dynamic part of the action, $module, is the module slug. |
||
| 116 | * |
||
| 117 | * @since 3.0.0 |
||
| 118 | */ |
||
| 119 | do_action( 'jetpack_module_more_info_' . $module ); |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Filter the long description of a module. |
||
| 123 | * |
||
| 124 | * @since 3.5.0 |
||
| 125 | * |
||
| 126 | * @param string ob_get_clean() The module long description. |
||
| 127 | * @param string $module The module name. |
||
| 128 | */ |
||
| 129 | $module_array['long_description'] = apply_filters( 'jetpack_long_module_description', ob_get_clean(), $module ); |
||
| 130 | |||
| 131 | ob_start(); |
||
| 132 | /** |
||
| 133 | * Filter the search terms for a module |
||
| 134 | * |
||
| 135 | * Search terms are typically added to the module headers, under "Additional Search Queries". |
||
| 136 | * |
||
| 137 | * Use syntax: |
||
| 138 | * function jetpack_$module_search_terms( $terms ) { |
||
| 139 | * $terms = _x( 'term 1, term 2', 'search terms', 'jetpack' ); |
||
| 140 | * return $terms; |
||
| 141 | * } |
||
| 142 | * add_filter( 'jetpack_search_terms_$module', 'jetpack_$module_search_terms' ); |
||
| 143 | * |
||
| 144 | * @since 3.5.0 |
||
| 145 | * |
||
| 146 | * @param string The search terms (comma separated). |
||
| 147 | */ |
||
| 148 | echo apply_filters( 'jetpack_search_terms_' . $module, $module_array['additional_search_queries'] ); |
||
| 149 | $module_array['search_terms'] = ob_get_clean(); |
||
| 150 | |||
| 151 | $module_array['configurable'] = false; |
||
| 152 | if ( |
||
| 153 | current_user_can( 'manage_options' ) && |
||
| 154 | /** |
||
| 155 | * Allow the display of a configuration link in the Jetpack Settings screen. |
||
| 156 | * |
||
| 157 | * @since 3.0.0 |
||
| 158 | * |
||
| 159 | * @param string $module Module name. |
||
| 160 | * @param bool false Should the Configure module link be displayed? Default to false. |
||
| 161 | */ |
||
| 162 | apply_filters( 'jetpack_module_configurable_' . $module, false ) |
||
| 163 | ) { |
||
| 164 | $module_array['configurable'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( Jetpack::module_configuration_url( $module ) ), __( 'Configure', 'jetpack' ) ); |
||
| 165 | } |
||
| 166 | |||
| 167 | $modules[ $module ] = $module_array; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | uasort( $modules, array( $this->jetpack, 'sort_modules' ) ); |
||
| 172 | |||
| 173 | if ( ! Jetpack::is_active() ) { |
||
| 174 | uasort( $modules, array( __CLASS__, 'sort_requires_connection_last' ) ); |
||
| 175 | } |
||
| 176 | |||
| 177 | return $modules; |
||
| 178 | } |
||
| 179 | |||
| 259 |
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: