| Conditions | 16 |
| Paths | 16 |
| Total Lines | 65 |
| Code Lines | 47 |
| 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 |
||
| 153 | function check_plan_deactivate_modules( $page ) { |
||
| 154 | if ( |
||
| 155 | Jetpack::is_development_mode() |
||
| 156 | || ! in_array( |
||
| 157 | $page->base, |
||
| 158 | array( |
||
| 159 | 'toplevel_page_jetpack', |
||
| 160 | 'admin_page_jetpack_modules', |
||
| 161 | 'jetpack_page_vaultpress', |
||
| 162 | 'jetpack_page_stats', |
||
| 163 | 'jetpack_page_akismet-key-config' |
||
| 164 | ) |
||
| 165 | ) |
||
| 166 | || true === self::$plan_checked |
||
| 167 | ) { |
||
| 168 | return false; |
||
| 169 | } |
||
| 170 | |||
| 171 | self::$plan_checked = true; |
||
| 172 | $previous = get_option( 'jetpack_active_plan', '' ); |
||
| 173 | $response = rest_do_request( new WP_REST_Request( 'GET', '/jetpack/v4/site' ) ); |
||
| 174 | |||
| 175 | if ( ! is_object( $response ) || $response->is_error() ) { |
||
| 176 | |||
| 177 | // If we can't get information about the current plan we don't do anything |
||
| 178 | self::$plan_checked = true; |
||
| 179 | return; |
||
| 180 | } |
||
| 181 | |||
| 182 | $current = $response->get_data(); |
||
| 183 | $current = json_decode( $current['data'] ); |
||
| 184 | |||
| 185 | $to_deactivate = array(); |
||
| 186 | if ( isset( $current->plan->product_slug ) ) { |
||
| 187 | if ( |
||
| 188 | empty( $previous ) |
||
| 189 | || ! isset( $previous['product_slug'] ) |
||
| 190 | || $previous['product_slug'] !== $current->plan->product_slug |
||
| 191 | ) { |
||
| 192 | $active = Jetpack::get_active_modules(); |
||
| 193 | switch ( $current->plan->product_slug ) { |
||
| 194 | case 'jetpack_free': |
||
| 195 | $to_deactivate = array( 'seo-tools', 'videopress' ); |
||
| 196 | break; |
||
| 197 | case 'jetpack_personal': |
||
| 198 | case 'jetpack_personal_monthly': |
||
| 199 | $to_deactivate = array( 'seo-tools', 'videopress' ); |
||
| 200 | break; |
||
| 201 | case 'jetpack_premium': |
||
| 202 | case 'jetpack_premium_monthly': |
||
| 203 | $to_deactivate = array( 'seo-tools' ); |
||
| 204 | break; |
||
| 205 | } |
||
| 206 | $to_deactivate = array_intersect( $active, $to_deactivate ); |
||
| 207 | if ( ! empty( $to_deactivate ) ) { |
||
| 208 | Jetpack::update_active_modules( array_filter( array_diff( $active, $to_deactivate ) ) ); |
||
| 209 | } |
||
| 210 | } |
||
| 211 | } |
||
| 212 | return array( |
||
| 213 | 'previous' => $previous, |
||
| 214 | 'current' => $current, |
||
| 215 | 'deactivate' => $to_deactivate |
||
| 216 | ); |
||
| 217 | } |
||
| 218 | } |
||
| 219 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.