woothemes/woocommerce

View on GitHub
includes/admin/class-wc-admin-notices.php

Summary

Maintainability
D
2 days
Test Coverage

File class-wc-admin-notices.php has 363 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Display notices in admin
 *
 * @package WooCommerce\Admin
Severity: Minor
Found in includes/admin/class-wc-admin-notices.php - About 4 hrs to fix

    WC_Admin_Notices has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WC_Admin_Notices {
    
        /**
         * Stores notices.
         *
    Severity: Minor
    Found in includes/admin/class-wc-admin-notices.php - About 4 hrs to fix

      Function template_file_check_notice has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function template_file_check_notice() {
              $core_templates = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates' );
              $outdated       = false;
      
              foreach ( $core_templates as $file ) {
      Severity: Minor
      Found in includes/admin/class-wc-admin-notices.php - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function prepare_note_with_nonce has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function prepare_note_with_nonce( $response ) {
              if ( 'wc-update-db-reminder' !== $response->data['name'] || ! isset( $response->data['actions'] ) ) {
                  return $response;
              }
      
      
      Severity: Minor
      Found in includes/admin/class-wc-admin-notices.php - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function output_custom_notices has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function output_custom_notices() {
              $notices = self::get_notices();
      
              if ( ! empty( $notices ) ) {
                  foreach ( $notices as $notice ) {
      Severity: Minor
      Found in includes/admin/class-wc-admin-notices.php - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method wp_php_min_requirements_notice has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function wp_php_min_requirements_notice() {
              if ( apply_filters( 'woocommerce_hide_php_wp_nag', get_user_meta( get_current_user_id(), 'dismissed_' . WC_PHP_MIN_REQUIREMENTS_NOTICE . '_notice', true ) ) ) {
                  self::remove_notice( WC_PHP_MIN_REQUIREMENTS_NOTICE );
                  return;
              }
      Severity: Minor
      Found in includes/admin/class-wc-admin-notices.php - About 1 hr to fix

        Method template_file_check_notice has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function template_file_check_notice() {
                $core_templates = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates' );
                $outdated       = false;
        
                foreach ( $core_templates as $file ) {
        Severity: Minor
        Found in includes/admin/class-wc-admin-notices.php - About 1 hr to fix

          Function no_shipping_methods_notice has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function no_shipping_methods_notice() {
                  if ( wc_shipping_enabled() && ( empty( $_GET['page'] ) || empty( $_GET['tab'] ) || 'wc-settings' !== $_GET['page'] || 'shipping' !== $_GET['tab'] ) ) { // WPCS: input var ok, CSRF ok.
                      $product_count = wp_count_posts( 'product' );
                      $method_count  = wc_get_shipping_method_count();
          
          
          Severity: Minor
          Found in includes/admin/class-wc-admin-notices.php - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function update_notice has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function update_notice() {
                  $screen    = get_current_screen();
                  $screen_id = $screen ? $screen->id : '';
                  if ( WC()->is_wc_admin_active() && in_array( $screen_id, wc_get_screen_ids(), true ) ) {
                      return;
          Severity: Minor
          Found in includes/admin/class-wc-admin-notices.php - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function add_notices has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function add_notices() {
                  $notices = self::get_notices();
          
                  if ( empty( $notices ) ) {
                      return;
          Severity: Minor
          Found in includes/admin/class-wc-admin-notices.php - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function wp_php_min_requirements_notice has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function wp_php_min_requirements_notice() {
                  if ( apply_filters( 'woocommerce_hide_php_wp_nag', get_user_meta( get_current_user_id(), 'dismissed_' . WC_PHP_MIN_REQUIREMENTS_NOTICE . '_notice', true ) ) ) {
                      self::remove_notice( WC_PHP_MIN_REQUIREMENTS_NOTICE );
                      return;
                  }
          Severity: Minor
          Found in includes/admin/class-wc-admin-notices.php - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function hide_notices has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function hide_notices() {
                  if ( isset( $_GET['wc-hide-notice'] ) && isset( $_GET['_wc_notice_nonce'] ) ) { // WPCS: input var ok, CSRF ok.
                      if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wc_notice_nonce'] ) ), 'woocommerce_hide_notices_nonce' ) ) { // WPCS: input var ok, CSRF ok.
                          wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
                      }
          Severity: Minor
          Found in includes/admin/class-wc-admin-notices.php - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function legacy_shipping_notice has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function legacy_shipping_notice() {
                  $maybe_load_legacy_methods = array( 'flat_rate', 'free_shipping', 'international_delivery', 'local_delivery', 'local_pickup' );
                  $enabled                   = false;
          
                  foreach ( $maybe_load_legacy_methods as $method ) {
          Severity: Minor
          Found in includes/admin/class-wc-admin-notices.php - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

                      if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
                          $theme_file = get_stylesheet_directory() . '/' . $file;
                      } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) {
                          $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file;
                      } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
          Severity: Major
          Found in includes/admin/class-wc-admin-notices.php and 1 other location - About 4 hrs to fix
          includes/class-wc-tracker.php on lines 606..616

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 171.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status