| Conditions | 12 |
| Paths | 12 |
| Total 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 //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
| 28 | |||
| 29 | // Bail if there was an error or malformed response. |
||
| 30 | if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) { |
||
| 31 | return false; |
||
| 32 | } |
||
| 33 | |||
| 34 | // Decode the results. |
||
| 35 | $results = json_decode( $response['body'], true ); |
||
| 36 | |||
| 37 | // Bail if there were no results or plan details returned. |
||
| 38 | if ( ! is_array( $results ) || ! isset( $results['plan'] ) ) { |
||
| 39 | return false; |
||
| 40 | } |
||
| 41 | |||
| 42 | // Store the option and return true if updated. |
||
| 43 | return update_option( 'jetpack_active_plan', $results['plan'], true ); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get the plan that this Jetpack site is currently using. |
||
| 48 | * |
||
| 49 | * @uses get_option() |
||
| 50 | * |
||
| 51 | * @access public |
||
| 52 | * @static |
||
| 53 | * |
||
| 54 | * @return array Active Jetpack plan details |
||
| 55 | */ |
||
| 56 | public static function get() { |
||
| 57 | global $active_plan_cache; |
||
| 58 | |||
| 59 | // this can be expensive to compute so we cache for the duration of a request. |
||
| 60 | if ( is_array( $active_plan_cache ) && ! empty( $active_plan_cache ) ) { |
||
| 61 | return $active_plan_cache; |
||
| 62 | } |
||
| 63 | |||
| 64 | $plan = get_option( 'jetpack_active_plan', array() ); |
||
| 65 | |||
| 66 | // Set the default options. |
||
| 67 | $plan = wp_parse_args( |
||
| 68 | $plan, |
||
| 69 | array( |
||
| 70 | 'product_slug' => 'jetpack_free', |
||
| 71 | 'class' => 'free', |
||
| 72 | 'features' => array( |
||
| 73 | 'active' => array(), |
||
| 74 | ), |
||
| 75 | ) |
||
| 184 |