woothemes/woocommerce

View on GitHub
includes/class-wc-tax.php

Summary

Maintainability
F
5 days
Test Coverage

File class-wc-tax.php has 667 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Tax calculation and rate finding class.
 *
 * @package WooCommerce\Classes
Severity: Major
Found in includes/class-wc-tax.php - About 1 day to fix

    WC_Tax has 46 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WC_Tax {
    
        /**
         * Precision.
         *
    Severity: Minor
    Found in includes/class-wc-tax.php - About 6 hrs to fix

      Function get_shipping_tax_rates has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function get_shipping_tax_rates( $tax_class = null, $customer = null ) {
              // See if we have an explicitly set shipping tax class.
              $shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );
      
              if ( 'inherit' !== $shipping_tax_class ) {
      Severity: Minor
      Found in includes/class-wc-tax.php - About 3 hrs 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 calc_exclusive_tax has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function calc_exclusive_tax( $price, $rates ) {
              $taxes = array();
      
              if ( ! empty( $rates ) ) {
                  foreach ( $rates as $key => $rate ) {
      Severity: Minor
      Found in includes/class-wc-tax.php - About 2 hrs 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 get_matched_tax_rates has 66 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function get_matched_tax_rates( $country, $state, $postcode, $city, $tax_class ) {
              global $wpdb;
      
              // Query criteria - these will be ANDed.
              $criteria   = array();
      Severity: Major
      Found in includes/class-wc-tax.php - About 2 hrs to fix

        Method get_shipping_tax_rates has 63 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function get_shipping_tax_rates( $tax_class = null, $customer = null ) {
                // See if we have an explicitly set shipping tax class.
                $shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );
        
                if ( 'inherit' !== $shipping_tax_class ) {
        Severity: Major
        Found in includes/class-wc-tax.php - About 2 hrs to fix

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

              private static function sort_rates_callback( $rate1, $rate2 ) {
                  if ( $rate1->tax_rate_priority !== $rate2->tax_rate_priority ) {
                      return $rate1->tax_rate_priority < $rate2->tax_rate_priority ? -1 : 1; // ASC.
                  }
          
          
          Severity: Minor
          Found in includes/class-wc-tax.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 calc_exclusive_tax has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function calc_exclusive_tax( $price, $rates ) {
                  $taxes = array();
          
                  if ( ! empty( $rates ) ) {
                      foreach ( $rates as $key => $rate ) {
          Severity: Minor
          Found in includes/class-wc-tax.php - About 1 hr to fix

            Method create_tax_class has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function create_tax_class( $name, $slug = '' ) {
                    global $wpdb;
            
                    if ( empty( $name ) ) {
                        return new WP_Error( 'tax_class_invalid_name', __( 'Tax class requires a valid name', 'woocommerce' ) );
            Severity: Minor
            Found in includes/class-wc-tax.php - About 1 hr to fix

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

                  private static function sort_rates_callback( $rate1, $rate2 ) {
                      if ( $rate1->tax_rate_priority !== $rate2->tax_rate_priority ) {
                          return $rate1->tax_rate_priority < $rate2->tax_rate_priority ? -1 : 1; // ASC.
                      }
              
              
              Severity: Minor
              Found in includes/class-wc-tax.php - About 1 hr to fix

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

                    private static function get_matched_tax_rates( $country, $state, $postcode, $city, $tax_class ) {
                        global $wpdb;
                
                        // Query criteria - these will be ANDed.
                        $criteria   = array();
                Severity: Minor
                Found in includes/class-wc-tax.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 calc_inclusive_tax has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function calc_inclusive_tax( $price, $rates ) {
                        $taxes          = array();
                        $compound_rates = array();
                        $regular_rates  = array();
                
                
                Severity: Minor
                Found in includes/class-wc-tax.php - About 1 hr to fix

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

                      public static function get_rates_for_tax_class( $tax_class ) {
                          global $wpdb;
                  
                          $tax_class = self::format_tax_rate_class( $tax_class );
                  
                  
                  Severity: Minor
                  Found in includes/class-wc-tax.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

                  Method get_matched_tax_rates has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      private static function get_matched_tax_rates( $country, $state, $postcode, $city, $tax_class ) {
                  Severity: Minor
                  Found in includes/class-wc-tax.php - About 35 mins to fix

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

                        private static function prepare_tax_rate( $tax_rate ) {
                            foreach ( $tax_rate as $key => $value ) {
                                if ( method_exists( __CLASS__, 'format_' . $key ) ) {
                                    if ( 'tax_rate_state' === $key ) {
                                        $tax_rate[ $key ] = call_user_func( array( __CLASS__, 'format_' . $key ), sanitize_key( $value ) );
                    Severity: Minor
                    Found in includes/class-wc-tax.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

                    Avoid too many return statements within this method.
                    Open

                                return $rate1->city_count < $rate2->city_count ? 1 : -1;
                    Severity: Major
                    Found in includes/class-wc-tax.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return $rate1->tax_rate_id < $rate2->tax_rate_id ? -1 : 1;
                      Severity: Major
                      Found in includes/class-wc-tax.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return -1;
                        Severity: Major
                        Found in includes/class-wc-tax.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return $rate1->postcode_count < $rate2->postcode_count ? 1 : -1;
                          Severity: Major
                          Found in includes/class-wc-tax.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return strcmp( $rate1->tax_rate_state, $rate2->tax_rate_state ) > 0 ? 1 : -1;
                            Severity: Major
                            Found in includes/class-wc-tax.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return 1;
                              Severity: Major
                              Found in includes/class-wc-tax.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return array(
                                            'name' => $name,
                                            'slug' => $slug,
                                        );
                                Severity: Major
                                Found in includes/class-wc-tax.php - About 30 mins to fix

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

                                      public static function find_shipping_rates( $args = array() ) {
                                          $rates          = self::find_rates( $args );
                                          $shipping_rates = array();
                                  
                                          if ( is_array( $rates ) ) {
                                  Severity: Minor
                                  Found in includes/class-wc-tax.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 calc_inclusive_tax has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public static function calc_inclusive_tax( $price, $rates ) {
                                          $taxes          = array();
                                          $compound_rates = array();
                                          $regular_rates  = array();
                                  
                                  
                                  Severity: Minor
                                  Found in includes/class-wc-tax.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

                                  There are no issues that match your filters.

                                  Category
                                  Status