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