Conditions | 104 |
Paths | 0 |
Total Lines | 317 |
Code Lines | 178 |
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 |
||
247 | public function v700_upgrades() { |
||
248 | // 1. Default all event tracking and tracking to GA + JS respectively |
||
249 | // 3a Set tracking_mode to use analytics.js |
||
250 | $this->new_settings['tracking_mode' ] = 'analytics'; |
||
251 | |||
252 | |||
253 | // 3b Set events mode to use JS if the events mode is not set explicitly to none |
||
254 | if ( empty( $this->new_settings['events_mode' ] ) || $this->new_settings['events_mode' ] !== 'none' ) { |
||
255 | $this->new_settings['events_mode' ] = 'js'; |
||
256 | } |
||
257 | |||
258 | // 2. Migrate manual UA codes |
||
259 | // 2a Manual UA has the lowest priority |
||
260 | if ( ! empty( $this->new_settings['manual_ua_code' ] ) ) { |
||
261 | // Set as manual UA code |
||
262 | is_network_admin() ? update_site_option( 'monsterinsights_network_profile', array( 'manual' => $this->new_settings['manual_ua_code' ] ) ) : update_option( 'monsterinsights_site_profile', array( 'manual' => $this->new_settings['manual_ua_code' ] ) ); |
||
263 | } |
||
264 | |||
265 | // 2b Then try the oAuth UA code |
||
266 | if ( ! empty( $this->new_settings['analytics_profile_code' ] ) ) { |
||
267 | // Set as manual UA code |
||
268 | is_network_admin() ? update_site_option( 'monsterinsights_network_profile', array( 'manual' => $this->new_settings['analytics_profile_code' ] ) ) : update_option( 'monsterinsights_site_profile', array( 'manual' => $this->new_settings['analytics_profile_code' ] ) ); |
||
269 | } |
||
270 | |||
271 | // 3. Migrate License keys |
||
272 | if ( is_multisite() ) { |
||
273 | $ms_license = get_site_option( 'monsterinsights_license', '' ); |
||
274 | if ( $ms_license ) { |
||
275 | update_site_option( 'monsterinsights_network_license_updates', get_site_option( 'monsterinsights_license_updates', '' ) ); |
||
276 | update_site_option( 'monsterinsights_network_license', $ms_license ); |
||
277 | } |
||
278 | } |
||
279 | } |
||
280 | |||
281 | /** |
||
282 | * Upgrade routine for the new settings panel, onboarding wizard, and the internal-as-outbound v2 settings system. |
||
283 | */ |
||
284 | public function v740_upgrades() { |
||
285 | |||
286 | // 1. Settings Conversions: |
||
287 | // Convert affiliate field to repeater format |
||
288 | if ( ! empty( $this->new_settings['track_internal_as_outbound'] ) ) { |
||
289 | $affiliate_old_paths = $this->new_settings['track_internal_as_outbound']; |
||
290 | $affiliate_old_label = isset( $this->new_settings['track_internal_as_label'] ) ? $this->new_settings['track_internal_as_label'] : ''; |
||
291 | |||
292 | $new_paths = explode( ',', $affiliate_old_paths ); |
||
293 | |||
294 | $this->new_settings['affiliate_links'] = array(); |
||
295 | if ( ! empty( $new_paths ) ) { |
||
296 | $this->new_settings['enable_affiliate_links'] = true; |
||
297 | foreach ( $new_paths as $new_path ) { |
||
298 | $this->new_settings['affiliate_links'][] = array( |
||
299 | 'path' => $new_path, |
||
300 | 'label' => $affiliate_old_label, |
||
301 | ); |
||
302 | } |
||
303 | } |
||
304 | |||
305 | $settings = array( |
||
306 | 'track_internal_as_outbound', |
||
307 | 'track_internal_as_label', |
||
308 | ); |
||
309 | foreach ( $settings as $setting ) { |
||
310 | if ( ! empty( $this->new_settings[ $setting ] ) ) { |
||
311 | unset( $this->new_settings[ $setting ] ); |
||
312 | } |
||
313 | } |
||
314 | } |
||
315 | |||
316 | // Update option to disable just reports or also the dashboard widget. |
||
317 | if ( isset( $this->new_settings['dashboards_disabled'] ) && $this->new_settings['dashboards_disabled'] ) { |
||
318 | $this->new_settings['dashboards_disabled'] = 'disabled'; |
||
319 | } |
||
320 | |||
321 | $this->new_settings['tracking_mode'] = 'analytics'; |
||
322 | $this->new_settings['events_mode'] = 'js'; |
||
323 | |||
324 | // If opted in during allow_tracking era, move that over |
||
325 | if ( ! empty( $this->new_settings['allow_tracking'] ) ) { |
||
326 | $this->new_settings['anonymous_data'] = 1; |
||
327 | } |
||
328 | |||
329 | // 2. Remove Yoast stuff |
||
330 | delete_option( 'yoast-ga-access_token' ); |
||
331 | delete_option( 'yoast-ga-refresh_token' ); |
||
332 | delete_option( 'yst_ga' ); |
||
333 | delete_option( 'yst_ga_api' ); |
||
334 | |||
335 | |||
336 | // 3. Remove fake settings from other plugins using our key for some reason and old settings of ours |
||
337 | $settings = array( |
||
338 | 'debug_mode', |
||
339 | 'track_download_as', |
||
340 | 'analytics_profile', |
||
341 | 'analytics_profile_code', |
||
342 | 'analytics_profile_name', |
||
343 | 'manual_ua_code', |
||
344 | 'track_outbound', |
||
345 | 'track_download_as', |
||
346 | 'enhanced_link_attribution', |
||
347 | 'oauth_version', |
||
348 | 'monsterinsights_oauth_status', |
||
349 | 'firebug_lite', |
||
350 | 'google_auth_code', |
||
351 | 'allow_tracking', |
||
352 | ); |
||
353 | |||
354 | foreach ( $settings as $setting ) { |
||
355 | if ( ! empty( $this->new_settings[ $setting ] ) ) { |
||
356 | unset( $this->new_settings[ $setting ] ); |
||
357 | } |
||
358 | } |
||
359 | |||
360 | $settings = array( |
||
361 | '_repeated', |
||
362 | 'ajax', |
||
363 | 'asmselect0', |
||
364 | 'bawac_force_nonce', |
||
365 | 'icl_post_language', |
||
366 | 'saved_values', |
||
367 | 'mlcf_email', |
||
368 | 'mlcf_name', |
||
369 | 'cron_failed', |
||
370 | 'undefined', |
||
371 | 'cf_email', |
||
372 | 'cf_message', |
||
373 | 'cf_name', |
||
374 | 'cf_number', |
||
375 | 'cf_phone', |
||
376 | 'cf_subject', |
||
377 | 'content', |
||
378 | 'credentials', |
||
379 | 'cron_failed', |
||
380 | 'cron_last_run', |
||
381 | 'global-css', |
||
382 | 'grids', |
||
383 | 'page', |
||
384 | 'punch-fonts', |
||
385 | 'return_tab', |
||
386 | 'skins', |
||
387 | 'navigation-skins', |
||
388 | 'title', |
||
389 | 'type', |
||
390 | 'wpcf_email', |
||
391 | 'wpcf_your_name', |
||
392 | ); |
||
393 | |||
394 | foreach ( $settings as $setting ) { |
||
395 | if ( ! empty( $this->new_settings[ $setting ] ) ) { |
||
396 | unset( $this->new_settings[ $setting ] ); |
||
397 | } |
||
398 | } |
||
399 | |||
400 | // 4. Remove old crons |
||
401 | if ( wp_next_scheduled( 'monsterinsights_daily_cron' ) ) { |
||
402 | wp_clear_scheduled_hook( 'monsterinsights_daily_cron' ); |
||
403 | } |
||
404 | if ( wp_next_scheduled( 'monsterinsights_send_tracking_data' ) ) { |
||
405 | wp_clear_scheduled_hook( 'monsterinsights_send_tracking_data' ); |
||
406 | } |
||
407 | |||
408 | if ( wp_next_scheduled( 'monsterinsights_send_tracking_checkin' ) ) { |
||
409 | wp_clear_scheduled_hook( 'monsterinsights_send_tracking_checkin' ); |
||
410 | } |
||
411 | |||
412 | if ( wp_next_scheduled( 'monsterinsights_weekly_cron' ) ) { |
||
413 | wp_clear_scheduled_hook( 'monsterinsights_weekly_cron' ); |
||
414 | } |
||
415 | |||
416 | if ( wp_next_scheduled( 'yst_ga_aggregate_data' ) ) { |
||
417 | wp_clear_scheduled_hook( 'yst_ga_aggregate_data' ); |
||
418 | } |
||
419 | |||
420 | delete_option( 'monsterinsights_tracking_last_send' ); |
||
421 | delete_option( 'mi_tracking_last_send' ); |
||
422 | |||
423 | // 5. Remove old option |
||
424 | delete_option( 'monsterinsights_settings_version' ); |
||
425 | } |
||
426 | |||
427 | |||
428 | /** |
||
429 | * Upgrade routine |
||
430 | */ |
||
431 | public function v750_upgrades() { |
||
432 | // 1. One time re-prompt for anonymous data (due to migration bug now fixed) |
||
433 | // if ( ! monsterinsights_is_pro_version() ) { |
||
434 | // if ( empty( $this->new_settings[ 'anonymous_data' ] ) ) { |
||
435 | // update_option( 'monsterinsights_tracking_notice', 0 ); |
||
436 | // } |
||
437 | // } |
||
438 | // |
||
439 | // 2. Clear old settings ( 'tracking_mode','events_mode',) |
||
440 | } |
||
441 | } |
||
442 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.