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 |
||
81 | function get_modules() { |
||
82 | include_once( JETPACK__PLUGIN_DIR . 'modules/module-info.php' ); |
||
83 | $available_modules = Jetpack::get_available_modules(); |
||
84 | $active_modules = Jetpack::get_active_modules(); |
||
85 | $modules = array(); |
||
86 | $jetpack_active = Jetpack::is_active() || Jetpack::is_development_mode(); |
||
87 | $overrides = Jetpack_Modules_Overrides::instance(); |
||
88 | foreach ( $available_modules as $module ) { |
||
89 | if ( $module_array = Jetpack::get_module( $module ) ) { |
||
90 | /** |
||
91 | * Filters each module's short description. |
||
92 | * |
||
93 | * @since 3.0.0 |
||
94 | * |
||
95 | * @param string $module_array['description'] Module description. |
||
96 | * @param string $module Module slug. |
||
97 | */ |
||
98 | $short_desc = apply_filters( 'jetpack_short_module_description', $module_array['description'], $module ); |
||
99 | // Fix: correct multibyte strings truncate with checking for mbstring extension |
||
100 | $short_desc_trunc = ( function_exists( 'mb_strlen' ) ) |
||
101 | ? ( ( mb_strlen( $short_desc ) > 143 ) |
||
102 | ? mb_substr( $short_desc, 0, 140 ) . '...' |
||
103 | : $short_desc ) |
||
104 | : ( ( strlen( $short_desc ) > 143 ) |
||
105 | ? substr( $short_desc, 0, 140 ) . '...' |
||
106 | : $short_desc ); |
||
107 | |||
108 | $module_array['module'] = $module; |
||
109 | $module_array['activated'] = ( $jetpack_active ? in_array( $module, $active_modules ) : false ); |
||
110 | $module_array['deactivate_nonce'] = wp_create_nonce( 'jetpack_deactivate-' . $module ); |
||
111 | $module_array['activate_nonce'] = wp_create_nonce( 'jetpack_activate-' . $module ); |
||
112 | $module_array['available'] = self::is_module_available( $module_array ); |
||
113 | $module_array['short_description'] = $short_desc_trunc; |
||
114 | $module_array['configure_url'] = Jetpack::module_configuration_url( $module ); |
||
115 | $module_array['override'] = $overrides->get_module_override( $module ); |
||
116 | |||
117 | ob_start(); |
||
118 | /** |
||
119 | * Allow the display of a "Learn More" button. |
||
120 | * The dynamic part of the action, $module, is the module slug. |
||
121 | * |
||
122 | * @since 3.0.0 |
||
123 | */ |
||
124 | do_action( 'jetpack_learn_more_button_' . $module ); |
||
125 | $module_array['learn_more_button'] = ob_get_clean(); |
||
126 | |||
127 | ob_start(); |
||
128 | /** |
||
129 | * Allow the display of information text when Jetpack is connected to WordPress.com. |
||
130 | * The dynamic part of the action, $module, is the module slug. |
||
131 | * |
||
132 | * @since 3.0.0 |
||
133 | */ |
||
134 | do_action( 'jetpack_module_more_info_' . $module ); |
||
135 | |||
136 | /** |
||
137 | * Filter the long description of a module. |
||
138 | * |
||
139 | * @since 3.5.0 |
||
140 | * |
||
141 | * @param string ob_get_clean() The module long description. |
||
142 | * @param string $module The module name. |
||
143 | */ |
||
144 | $module_array['long_description'] = apply_filters( 'jetpack_long_module_description', ob_get_clean(), $module ); |
||
145 | |||
146 | ob_start(); |
||
147 | /** |
||
148 | * Filter the search terms for a module |
||
149 | * |
||
150 | * Search terms are typically added to the module headers, under "Additional Search Queries". |
||
151 | * |
||
152 | * Use syntax: |
||
153 | * function jetpack_$module_search_terms( $terms ) { |
||
154 | * $terms = _x( 'term 1, term 2', 'search terms', 'jetpack' ); |
||
155 | * return $terms; |
||
156 | * } |
||
157 | * add_filter( 'jetpack_search_terms_$module', 'jetpack_$module_search_terms' ); |
||
158 | * |
||
159 | * @since 3.5.0 |
||
160 | * |
||
161 | * @param string The search terms (comma separated). |
||
162 | */ |
||
163 | echo apply_filters( 'jetpack_search_terms_' . $module, $module_array['additional_search_queries'] ); |
||
164 | $module_array['search_terms'] = ob_get_clean(); |
||
165 | |||
166 | $module_array['configurable'] = false; |
||
167 | if ( |
||
168 | current_user_can( 'manage_options' ) && |
||
169 | /** |
||
170 | * Allow the display of a configuration link in the Jetpack Settings screen. |
||
171 | * |
||
172 | * @since 3.0.0 |
||
173 | * |
||
174 | * @param string $module Module name. |
||
175 | * @param bool false Should the Configure module link be displayed? Default to false. |
||
176 | */ |
||
177 | apply_filters( 'jetpack_module_configurable_' . $module, false ) |
||
178 | ) { |
||
179 | $module_array['configurable'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $module_array['configure_url'] ), __( 'Configure', 'jetpack' ) ); |
||
180 | } |
||
181 | |||
182 | $modules[ $module ] = $module_array; |
||
183 | } |
||
184 | } |
||
185 | |||
186 | uasort( $modules, array( $this->jetpack, 'sort_modules' ) ); |
||
187 | |||
188 | if ( ! Jetpack::is_active() ) { |
||
189 | uasort( $modules, array( __CLASS__, 'sort_requires_connection_last' ) ); |
||
190 | } |
||
191 | |||
192 | return $modules; |
||
193 | } |
||
194 | |||
292 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.