woocommerce/woocommerce

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

Summary

Maintainability
F
1 wk
Test Coverage

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

<?php
/**
 * WooCommerce cart
 *
 * The WooCommerce cart class stores cart data and active coupons as well as handling customer sessions and some cart related urls.
Severity: Major
Found in includes/class-wc-cart.php - About 2 days to fix

    WC_Cart has 110 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WC_Cart extends WC_Legacy_Cart {
    
        /**
         * Contains an array of cart items.
         *
    Severity: Major
    Found in includes/class-wc-cart.php - About 2 days to fix

      Function add_to_cart has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
      Open

          public function add_to_cart( $product_id = 0, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array() ) {
              try {
                  $product_id   = absint( $product_id );
                  $variation_id = absint( $variation_id );
      
      
      Severity: Minor
      Found in includes/class-wc-cart.php - About 1 day 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 add_to_cart has 150 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function add_to_cart( $product_id = 0, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array() ) {
              try {
                  $product_id   = absint( $product_id );
                  $variation_id = absint( $variation_id );
      
      
      Severity: Major
      Found in includes/class-wc-cart.php - About 6 hrs to fix

        Function apply_coupon has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            public function apply_coupon( $coupon_code ) {
                // Coupons are globally disabled.
                if ( ! wc_coupons_enabled() ) {
                    return false;
                }
        Severity: Minor
        Found in includes/class-wc-cart.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 check_customer_coupons has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            public function check_customer_coupons( $posted ) {
                foreach ( $this->get_applied_coupons() as $code ) {
                    $coupon = new WC_Coupon( $code );
        
                    if ( $coupon->is_valid() ) {
        Severity: Minor
        Found in includes/class-wc-cart.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 apply_coupon has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function apply_coupon( $coupon_code ) {
                // Coupons are globally disabled.
                if ( ! wc_coupons_enabled() ) {
                    return false;
                }
        Severity: Major
        Found in includes/class-wc-cart.php - About 2 hrs to fix

          Method check_customer_coupons has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function check_customer_coupons( $posted ) {
                  foreach ( $this->get_applied_coupons() as $code ) {
                      $coupon = new WC_Coupon( $code );
          
                      if ( $coupon->is_valid() ) {
          Severity: Minor
          Found in includes/class-wc-cart.php - About 1 hr to fix

            Function get_product_subtotal has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get_product_subtotal( $product, $quantity ) {
                    $price = $product->get_price();
            
                    if ( $product->is_taxable() ) {
            
            
            Severity: Minor
            Found in includes/class-wc-cart.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 generate_cart_id has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public function generate_cart_id( $product_id, $variation_id = 0, $variation = array(), $cart_item_data = array() ) {
                    $id_parts = array( $product_id );
            
                    if ( $variation_id && 0 !== $variation_id ) {
                        $id_parts[] = $variation_id;
            Severity: Minor
            Found in includes/class-wc-cart.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 get_tax_totals has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get_tax_totals() {
                    $shipping_taxes = $this->get_shipping_taxes(); // Shipping taxes are rounded differently, so we will subtract from all taxes, then round and then add them back.
                    $taxes          = $this->get_taxes();
                    $tax_totals     = array();
            
            
            Severity: Minor
            Found in includes/class-wc-cart.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 get_cart_shipping_total has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get_cart_shipping_total() {
            
                    // Default total assumes Free shipping.
                    $total = __( 'Free!', 'woocommerce' );
            
            
            Severity: Minor
            Found in includes/class-wc-cart.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 get_tax_totals has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function get_tax_totals() {
                    $shipping_taxes = $this->get_shipping_taxes(); // Shipping taxes are rounded differently, so we will subtract from all taxes, then round and then add them back.
                    $taxes          = $this->get_taxes();
                    $tax_totals     = array();
            
            
            Severity: Minor
            Found in includes/class-wc-cart.php - About 1 hr to fix

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

                  public function show_shipping() {
                      if ( ! wc_shipping_enabled() || ! $this->get_cart_contents() ) {
                          return false;
                      }
              
              
              Severity: Minor
              Found in includes/class-wc-cart.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 check_cart_item_stock has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function check_cart_item_stock() {
                      $error                    = new WP_Error();
                      $product_qty_in_cart      = $this->get_cart_item_quantities();
                      $current_session_order_id = isset( WC()->session->order_awaiting_payment ) ? absint( WC()->session->order_awaiting_payment ) : 0;
              
              
              Severity: Minor
              Found in includes/class-wc-cart.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_cart_subtotal has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function get_cart_subtotal( $compound = false ) {
                      /**
                       * If the cart has compound tax, we want to show the subtotal as cart + shipping + non-compound taxes (after discount).
                       */
                      if ( $compound ) {
              Severity: Minor
              Found in includes/class-wc-cart.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 is_coupon_emails_allowed has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function is_coupon_emails_allowed( $check_emails, $restrictions ) {
              
                      foreach ( $check_emails as $check_email ) {
                          // With a direct match we return true.
                          if ( in_array( $check_email, $restrictions, true ) ) {
              Severity: Minor
              Found in includes/class-wc-cart.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 add_to_cart has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public function add_to_cart( $product_id = 0, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array() ) {
              Severity: Minor
              Found in includes/class-wc-cart.php - About 35 mins to fix

                Avoid too many return statements within this method.
                Open

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

                  Avoid too many return statements within this method.
                  Open

                          return apply_filters( 'woocommerce_cart_ready_to_calc_shipping', true );
                  Severity: Major
                  Found in includes/class-wc-cart.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

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

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

                          public function get_cross_sells() {
                              $cross_sells = array();
                              $in_cart     = array();
                              if ( ! $this->is_empty() ) {
                                  foreach ( $this->get_cart() as $cart_item_key => $values ) {
                      Severity: Minor
                      Found in includes/class-wc-cart.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 needs_shipping has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function needs_shipping() {
                              if ( ! wc_shipping_enabled() || 0 === wc_get_shipping_method_count( true ) ) {
                                  return false;
                              }
                              $needs_shipping = false;
                      Severity: Minor
                      Found in includes/class-wc-cart.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 calculate_shipping has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function calculate_shipping() {
                              $this->shipping_methods = $this->needs_shipping() ? $this->get_chosen_shipping_methods( WC()->shipping()->calculate_shipping( $this->get_shipping_packages() ) ) : array();
                      
                              $shipping_taxes = wp_list_pluck( $this->shipping_methods, 'taxes' );
                              $merged_taxes   = array();
                      Severity: Minor
                      Found in includes/class-wc-cart.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_taxes_total has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function get_taxes_total( $compound = true, $display = true ) {
                              $total = 0;
                              $taxes = $this->get_taxes();
                              foreach ( $taxes as $key => $tax ) {
                                  if ( ! $compound && WC_Tax::is_compound( $key ) ) {
                      Severity: Minor
                      Found in includes/class-wc-cart.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