| Conditions | 11 |
| Paths | 33 |
| Total Lines | 92 |
| Lines | 14 |
| Ratio | 15.22 % |
| 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 |
||
| 96 | public static function get() { |
||
| 97 | // this can be expensive to compute so we cache for the duration of a request. |
||
| 98 | if ( is_array( self::$active_plan_cache ) && ! empty( self::$active_plan_cache ) ) { |
||
| 99 | return self::$active_plan_cache; |
||
| 100 | } |
||
| 101 | |||
| 102 | $plan = get_option( self::PLAN_OPTION, array() ); |
||
| 103 | |||
| 104 | // Set the default options. |
||
| 105 | $plan = wp_parse_args( |
||
| 106 | $plan, |
||
| 107 | array( |
||
| 108 | 'product_slug' => 'jetpack_free', |
||
| 109 | 'class' => 'free', |
||
| 110 | 'features' => array( |
||
| 111 | 'active' => array(), |
||
| 112 | ), |
||
| 113 | ) |
||
| 114 | ); |
||
| 115 | |||
| 116 | $supports = array(); |
||
| 117 | |||
| 118 | // Define what paid modules are supported by personal plans. |
||
| 119 | $personal_plans = array( |
||
| 120 | 'jetpack_personal', |
||
| 121 | 'jetpack_personal_monthly', |
||
| 122 | 'personal-bundle', |
||
| 123 | 'personal-bundle-monthly', |
||
| 124 | 'personal-bundle-2y', |
||
| 125 | ); |
||
| 126 | |||
| 127 | if ( in_array( $plan['product_slug'], $personal_plans, true ) ) { |
||
| 128 | // special support value, not a module but a separate plugin. |
||
| 129 | $supports[] = 'akismet'; |
||
| 130 | $plan['class'] = 'personal'; |
||
| 131 | } |
||
| 132 | |||
| 133 | // Define what paid modules are supported by premium plans. |
||
| 134 | $premium_plans = array( |
||
| 135 | 'jetpack_premium', |
||
| 136 | 'jetpack_premium_monthly', |
||
| 137 | 'value_bundle', |
||
| 138 | 'value_bundle-monthly', |
||
| 139 | 'value_bundle-2y', |
||
| 140 | ); |
||
| 141 | |||
| 142 | View Code Duplication | if ( in_array( $plan['product_slug'], $premium_plans, true ) ) { |
|
| 143 | $supports[] = 'akismet'; |
||
| 144 | $supports[] = 'simple-payments'; |
||
| 145 | $supports[] = 'vaultpress'; |
||
| 146 | $supports[] = 'videopress'; |
||
| 147 | $plan['class'] = 'premium'; |
||
| 148 | } |
||
| 149 | |||
| 150 | // Define what paid modules are supported by professional plans. |
||
| 151 | $business_plans = array( |
||
| 152 | 'jetpack_business', |
||
| 153 | 'jetpack_business_monthly', |
||
| 154 | 'business-bundle', |
||
| 155 | 'business-bundle-monthly', |
||
| 156 | 'business-bundle-2y', |
||
| 157 | 'ecommerce-bundle', |
||
| 158 | 'ecommerce-bundle-monthly', |
||
| 159 | 'ecommerce-bundle-2y', |
||
| 160 | 'vip', |
||
| 161 | ); |
||
| 162 | |||
| 163 | View Code Duplication | if ( in_array( $plan['product_slug'], $business_plans, true ) ) { |
|
| 164 | $supports[] = 'akismet'; |
||
| 165 | $supports[] = 'simple-payments'; |
||
| 166 | $supports[] = 'vaultpress'; |
||
| 167 | $supports[] = 'videopress'; |
||
| 168 | $plan['class'] = 'business'; |
||
| 169 | } |
||
| 170 | |||
| 171 | // get available features. |
||
| 172 | foreach ( Jetpack::get_available_modules() as $module_slug ) { |
||
| 173 | $module = Jetpack::get_module( $module_slug ); |
||
| 174 | if ( ! isset( $module ) || ! is_array( $module ) ) { |
||
| 175 | continue; |
||
| 176 | } |
||
| 177 | if ( in_array( 'free', $module['plan_classes'], true ) || in_array( $plan['class'], $module['plan_classes'], true ) ) { |
||
| 178 | $supports[] = $module_slug; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | $plan['supports'] = $supports; |
||
| 183 | |||
| 184 | self::$active_plan_cache = $plan; |
||
| 185 | |||
| 186 | return $plan; |
||
| 187 | } |
||
| 188 | |||
| 226 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..