| Conditions | 15 |
| Paths | 10 |
| Total Lines | 51 |
| 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 |
||
| 46 | public function check_videopress_availability() { |
||
| 47 | // It is available on Simple Sites having the appropriate a plan. |
||
| 48 | if ( |
||
| 49 | defined( 'IS_WPCOM' ) && IS_WPCOM |
||
| 50 | && method_exists( 'WPCOM_Store', 'get_bundle_subscription' ) |
||
| 51 | && method_exists( 'Store_Product_List', 'get_feature_list' ) |
||
| 52 | ) { |
||
| 53 | $current_plan = WPCOM_Store::get_bundle_subscription( get_current_blog_id() ); |
||
| 54 | $features = Store_Product_List::get_feature_list(); |
||
| 55 | foreach ( $features as $feature ) { |
||
| 56 | if ( 'videopress' === $feature['product_slug'] ) { |
||
| 57 | $has_feature = array_key_exists( $current_plan->product_id, $feature['plans'] ); |
||
| 58 | break; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | if ( isset( $has_feature ) && $has_feature ) { |
||
| 62 | return array( 'available' => true ); |
||
| 63 | } else { |
||
| 64 | return array( |
||
| 65 | 'available' => false, |
||
| 66 | 'unavailable_reason' => 'missing_plan', |
||
| 67 | ); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | // It is available on Jetpack Sites having the module active. |
||
| 72 | if ( |
||
| 73 | method_exists( 'Jetpack', 'is_active' ) && Jetpack::is_active() |
||
| 74 | && method_exists( 'Jetpack', 'is_module_active' ) |
||
| 75 | && method_exists( 'Jetpack', 'active_plan_supports' ) |
||
| 76 | ) { |
||
| 77 | if ( Jetpack::is_module_active( 'videopress' ) ) { |
||
| 78 | return array( 'available' => true ); |
||
| 79 | } elseif ( ! Jetpack::active_plan_supports( 'videopress' ) ) { |
||
| 80 | return array( |
||
| 81 | 'available' => false, |
||
| 82 | 'unavailable_reason' => 'missing_plan', |
||
| 83 | ); |
||
| 84 | } else { |
||
| 85 | return array( |
||
| 86 | 'available' => false, |
||
| 87 | 'unavailable_reason' => 'missing_module', |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | return array( |
||
| 93 | 'available' => false, |
||
| 94 | 'unavailable_reason' => 'unknown', |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | |||
| 178 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.