woocommerce/woocommerce

View on GitHub
includes/class-wc-cart-totals.php

Summary

Maintainability
F
3 days
Test Coverage

File class-wc-cart-totals.php has 442 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Cart totals calculation class.
 *
 * Methods are protected and class is final to keep this as an internal API.
Severity: Minor
Found in includes/class-wc-cart-totals.php - About 6 hrs to fix

    Function get_fees_from_cart has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function get_fees_from_cart() {
            $this->fees = array();
            $this->cart->calculate_fees();
    
            $fee_running_total = 0;
    Severity: Minor
    Found in includes/class-wc-cart-totals.php - About 4 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

    WC_Cart_Totals has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    final class WC_Cart_Totals {
        use WC_Item_Totals;
    
        /**
         * Reference to cart object.
    Severity: Minor
    Found in includes/class-wc-cart-totals.php - About 3 hrs to fix

      Function calculate_item_subtotals has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function calculate_item_subtotals() {
              $merged_subtotal_taxes = array(); // Taxes indexed by tax rate ID for storage later.
      
              $adjust_non_base_location_prices = apply_filters( 'woocommerce_adjust_non_base_location_prices', true );
              $is_customer_vat_exempt          = $this->cart->get_customer()->get_is_vat_exempt();
      Severity: Minor
      Found in includes/class-wc-cart-totals.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

      Function calculate_discounts has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function calculate_discounts() {
              $this->get_coupons_from_cart();
      
              $discounts = new WC_Discounts( $this->cart );
      
      
      Severity: Minor
      Found in includes/class-wc-cart-totals.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_fees_from_cart has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function get_fees_from_cart() {
              $this->fees = array();
              $this->cart->calculate_fees();
      
              $fee_running_total = 0;
      Severity: Minor
      Found in includes/class-wc-cart-totals.php - About 1 hr to fix

        Method calculate_discounts has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function calculate_discounts() {
                $this->get_coupons_from_cart();
        
                $discounts = new WC_Discounts( $this->cart );
        
        
        Severity: Minor
        Found in includes/class-wc-cart-totals.php - About 1 hr to fix

          Method calculate_item_subtotals has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function calculate_item_subtotals() {
                  $merged_subtotal_taxes = array(); // Taxes indexed by tax rate ID for storage later.
          
                  $adjust_non_base_location_prices = apply_filters( 'woocommerce_adjust_non_base_location_prices', true );
                  $is_customer_vat_exempt          = $this->cart->get_customer()->get_is_vat_exempt();
          Severity: Minor
          Found in includes/class-wc-cart-totals.php - About 1 hr to fix

            Method calculate_item_totals has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function calculate_item_totals() {
                    $this->get_items_from_cart();
                    $this->calculate_item_subtotals();
                    $this->calculate_discounts();
            
            
            Severity: Minor
            Found in includes/class-wc-cart-totals.php - About 1 hr to fix

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

                  protected function get_merged_taxes( $in_cents = false, $types = array( 'items', 'fees', 'shipping' ) ) {
                      $items = array();
                      $taxes = array();
              
                      if ( is_string( $types ) ) {
              Severity: Minor
              Found in includes/class-wc-cart-totals.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 calculate_item_totals has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function calculate_item_totals() {
                      $this->get_items_from_cart();
                      $this->calculate_item_subtotals();
                      $this->calculate_discounts();
              
              
              Severity: Minor
              Found in includes/class-wc-cart-totals.php - About 55 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 get_tax_class_costs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function get_tax_class_costs() {
                      $item_tax_classes     = wp_list_pluck( $this->items, 'tax_class' );
                      $shipping_tax_classes = wp_list_pluck( $this->shipping, 'tax_class' );
                      $fee_tax_classes      = wp_list_pluck( $this->fees, 'tax_class' );
                      $costs                = array_fill_keys( $item_tax_classes + $shipping_tax_classes + $fee_tax_classes, 0 );
              Severity: Minor
              Found in includes/class-wc-cart-totals.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 get_coupons_from_cart has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function get_coupons_from_cart() {
                      $this->coupons = $this->cart->get_coupons();
              
                      foreach ( $this->coupons as $coupon ) {
                          switch ( $coupon->get_discount_type() ) {
              Severity: Minor
              Found in includes/class-wc-cart-totals.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 combine_item_taxes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function combine_item_taxes( $item_taxes ) {
                      $merged_taxes = array();
                      foreach ( $item_taxes as $taxes ) {
                          foreach ( $taxes as $tax_id => $tax_amount ) {
                              if ( ! isset( $merged_taxes[ $tax_id ] ) ) {
              Severity: Minor
              Found in includes/class-wc-cart-totals.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 get_item_costs_by_tax_class has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function get_item_costs_by_tax_class() {
                      $tax_classes = array(
                          'non-taxable' => 0,
                      );
              
              
              Severity: Minor
              Found in includes/class-wc-cart-totals.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 sort_coupons_callback has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function sort_coupons_callback( $a, $b ) {
                      if ( $a->sort === $b->sort ) {
                          if ( $a->get_limit_usage_to_x_items() === $b->get_limit_usage_to_x_items() ) {
                              if ( $a->get_amount() === $b->get_amount() ) {
                                  return $b->get_id() - $a->get_id();
              Severity: Minor
              Found in includes/class-wc-cart-totals.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