woocommerce/woocommerce

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

Summary

Maintainability
F
3 days
Test Coverage

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

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

    Method status_widget_stock_rows has 72 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            private function status_widget_stock_rows( $is_wc_admin_disabled ) {
                global $wpdb;
    
                // Requires lookup table added in 3.6.
                if ( version_compare( get_option( 'woocommerce_db_version', null ), '3.6', '<' ) ) {
    Severity: Major
    Found in includes/admin/class-wc-admin-dashboard.php - About 2 hrs to fix

      Method network_orders has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              public function network_orders() {
                  $suffix  = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
                  $version = Constants::get_constant( 'WC_VERSION' );
      
                  wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), $version );
      Severity: Major
      Found in includes/admin/class-wc-admin-dashboard.php - About 2 hrs to fix

        Method status_widget has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                public function status_widget() {
                    $suffix  = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
                    $version = Constants::get_constant( 'WC_VERSION' );
        
                    wp_enqueue_script( 'wc-status-widget', WC()->plugin_url() . '/assets/js/admin/wc-status-widget' . $suffix . '.js', array( 'jquery' ), $version, true );
        Severity: Major
        Found in includes/admin/class-wc-admin-dashboard.php - About 2 hrs to fix

          Function status_widget_stock_rows has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

                  private function status_widget_stock_rows( $is_wc_admin_disabled ) {
                      global $wpdb;
          
                      // Requires lookup table added in 3.6.
                      if ( version_compare( get_option( 'woocommerce_db_version', null ), '3.6', '<' ) ) {
          Severity: Minor
          Found in includes/admin/class-wc-admin-dashboard.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 sales_sparkline has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  private function sales_sparkline( $reports, $is_wc_admin_disabled = false, $id = '', $type = 'sales' ) {
                      $days = max( 7, gmdate( 'd', current_time( 'timestamp' ) ) );
                      if ( $is_wc_admin_disabled ) {
                          return $reports->sales_sparkline( $id, $days, $type );
                      }
          Severity: Minor
          Found in includes/admin/class-wc-admin-dashboard.php - About 1 hr to fix

            Method status_widget_order_rows has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    private function status_widget_order_rows() {
                        if ( ! current_user_can( 'edit_shop_orders' ) ) {
                            return;
                        }
                        $on_hold_count    = 0;
            Severity: Minor
            Found in includes/admin/class-wc-admin-dashboard.php - About 1 hr to fix

              Function status_widget has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                      public function status_widget() {
                          $suffix  = Constants::is_true( 'SCRIPT_DEBUG' ) ? '' : '.min';
                          $version = Constants::get_constant( 'WC_VERSION' );
              
                          wp_enqueue_script( 'wc-status-widget', WC()->plugin_url() . '/assets/js/admin/wc-status-widget' . $suffix . '.js', array( 'jquery' ), $version, true );
              Severity: Minor
              Found in includes/admin/class-wc-admin-dashboard.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 sales_sparkline has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                      private function sales_sparkline( $reports, $is_wc_admin_disabled = false, $id = '', $type = 'sales' ) {
                          $days = max( 7, gmdate( 'd', current_time( 'timestamp' ) ) );
                          if ( $is_wc_admin_disabled ) {
                              return $reports->sales_sparkline( $id, $days, $type );
                          }
              Severity: Minor
              Found in includes/admin/class-wc-admin-dashboard.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 recent_reviews has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      public function recent_reviews() {
                          global $wpdb;
              
                          $query_from = apply_filters(
                              'woocommerce_report_recent_reviews_query_from',
              Severity: Minor
              Found in includes/admin/class-wc-admin-dashboard.php - About 1 hr to fix

                Method get_wc_admin_performance_data has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        private function get_wc_admin_performance_data() {
                            $request    = new \WP_REST_Request( 'GET', '/wc-analytics/reports/performance-indicators' );
                            $start_date = gmdate( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
                            $end_date   = gmdate( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
                            $request->set_query_params(
                Severity: Minor
                Found in includes/admin/class-wc-admin-dashboard.php - About 1 hr to fix

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

                          private function get_wc_admin_performance_data() {
                              $request    = new \WP_REST_Request( 'GET', '/wc-analytics/reports/performance-indicators' );
                              $start_date = gmdate( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
                              $end_date   = gmdate( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
                              $request->set_query_params(
                  Severity: Minor
                  Found in includes/admin/class-wc-admin-dashboard.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 __construct has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                          public function __construct() {
                              // Only hook in admin parts if the user has admin access.
                              if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'manage_woocommerce' ) || current_user_can( 'publish_shop_orders' ) ) {
                                  // If on network admin, only load the widget that works in that context and skip the rest.
                                  if ( is_multisite() && is_network_admin() ) {
                  Severity: Minor
                  Found in includes/admin/class-wc-admin-dashboard.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 recent_reviews has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                          public function recent_reviews() {
                              global $wpdb;
                  
                              $query_from = apply_filters(
                                  'woocommerce_report_recent_reviews_query_from',
                  Severity: Minor
                  Found in includes/admin/class-wc-admin-dashboard.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 ( 'sales' === $type ) {
                                  /* translators: 1: total income 2: days */
                                  $tooltip = sprintf( __( 'Sold %1$s worth in the last %2$d days', 'woocommerce' ), strip_tags( wc_price( $total ) ), $days );
                              } else {
                                  /* translators: 1: total items sold 2: days */
                  Severity: Minor
                  Found in includes/admin/class-wc-admin-dashboard.php and 1 other location - About 35 mins to fix
                  includes/admin/reports/class-wc-admin-report.php on lines 591..597

                  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 92.

                  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