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