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