Conditions | 13 |
Paths | 264 |
Total Lines | 121 |
Code Lines | 45 |
Lines | 17 |
Ratio | 14.05 % |
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 | View Code Duplication | if ( Jetpack::is_active() && has_action( 'jetpack_module_more_info_connected_' . $module ) ) { |
|
115 | /** |
||
116 | * Allow the display of information text when Jetpack is connected to WordPress.com. |
||
117 | * The dynamic part of the action, $module, is the module slug. |
||
118 | * |
||
119 | * @since 3.0.0 |
||
120 | */ |
||
121 | do_action( 'jetpack_module_more_info_connected_' . $module ); |
||
122 | } else { |
||
123 | /** |
||
124 | * Allow the display of information text when Jetpack is connected to WordPress.com. |
||
125 | * The dynamic part of the action, $module, is the module slug. |
||
126 | * |
||
127 | * @since 3.0.0 |
||
128 | */ |
||
129 | do_action( 'jetpack_module_more_info_' . $module ); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Filter the long description of a module. |
||
134 | * |
||
135 | * @since 3.5.0 |
||
136 | * |
||
137 | * @param string ob_get_clean() The module long description. |
||
138 | * @param string $module The module name. |
||
139 | */ |
||
140 | $module_array['long_description'] = apply_filters( 'jetpack_long_module_description', ob_get_clean(), $module ); |
||
141 | |||
142 | ob_start(); |
||
143 | /** |
||
144 | * Filter the search terms for a module |
||
145 | * |
||
146 | * Search terms are typically added to the module headers, under "Additional Search Queries". |
||
147 | * |
||
148 | * Use syntax: |
||
149 | * function jetpack_$module_search_terms( $terms ) { |
||
150 | * $terms = _x( 'term 1, term 2', 'search terms', 'jetpack' ); |
||
151 | * return $terms; |
||
152 | * } |
||
153 | * add_filter( 'jetpack_search_terms_$module', 'jetpack_$module_search_terms' ); |
||
154 | * |
||
155 | * @since 3.5.0 |
||
156 | * |
||
157 | * @param string The search terms (comma separated). |
||
158 | */ |
||
159 | echo apply_filters( 'jetpack_search_terms_' . $module, $module_array['additional_search_queries'] ); |
||
160 | $module_array['search_terms'] = ob_get_clean(); |
||
161 | |||
162 | $module_array['configurable'] = false; |
||
163 | if ( |
||
164 | current_user_can( 'manage_options' ) && |
||
165 | /** |
||
166 | * Allow the display of a configuration link in the Jetpack Settings screen. |
||
167 | * |
||
168 | * @since 3.0.0 |
||
169 | * |
||
170 | * @param string $module Module name. |
||
171 | * @param bool false Should the Configure module link be displayed? Default to false. |
||
172 | */ |
||
173 | apply_filters( 'jetpack_module_configurable_' . $module, false ) |
||
174 | ) { |
||
175 | $module_array['configurable'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( Jetpack::module_configuration_url( $module ) ), __( 'Configure', 'jetpack' ) ); |
||
176 | } |
||
177 | |||
178 | $modules[ $module ] = $module_array; |
||
179 | } |
||
180 | } |
||
181 | |||
182 | uasort( $modules, array( $this->jetpack, 'sort_modules' ) ); |
||
183 | |||
184 | if ( ! Jetpack::is_active() ) { |
||
185 | uasort( $modules, array( __CLASS__, 'sort_requires_connection_last' ) ); |
||
186 | } |
||
187 | |||
188 | return $modules; |
||
189 | } |
||
190 | |||
270 |