woothemes/woocommerce

View on GitHub
includes/legacy/abstract-wc-legacy-order.php

Summary

Maintainability
F
5 days
Test Coverage

File abstract-wc-legacy-order.php has 435 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

Severity: Minor
Found in includes/legacy/abstract-wc-legacy-order.php - About 6 hrs to fix

    WC_Abstract_Legacy_Order has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class WC_Abstract_Legacy_Order extends WC_Data {
    
        /**
         * Add coupon code to the order.
         * @param string|array $code
    Severity: Minor
    Found in includes/legacy/abstract-wc-legacy-order.php - About 4 hrs to fix

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

          public function __get( $key ) {
              wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '3.0' );
      
              if ( 'completed_date' === $key ) {
                  return $this->get_date_completed() ? gmdate( 'Y-m-d H:i:s', $this->get_date_completed()->getOffsetTimestamp() ) : '';
      Severity: Minor
      Found in includes/legacy/abstract-wc-legacy-order.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 update_product has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          public function update_product( $item, $product, $args ) {
              wc_deprecated_function( 'WC_Order::update_product', '3.0', 'an interaction with the WC_Order_Item_Product class' );
              if ( is_numeric( $item ) ) {
                  $item = $this->get_item( $item );
              }
      Severity: Minor
      Found in includes/legacy/abstract-wc-legacy-order.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 has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function __get( $key ) {
              wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '3.0' );
      
              if ( 'completed_date' === $key ) {
                  return $this->get_date_completed() ? gmdate( 'Y-m-d H:i:s', $this->get_date_completed()->getOffsetTimestamp() ) : '';
      Severity: Minor
      Found in includes/legacy/abstract-wc-legacy-order.php - About 2 hrs to fix

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

            public function legacy_set_total( $amount, $total_type = 'total' ) {
                if ( ! in_array( $total_type, array( 'shipping', 'tax', 'shipping_tax', 'total', 'cart_discount', 'cart_discount_tax' ) ) ) {
                    return false;
                }
        
        
        Severity: Minor
        Found in includes/legacy/abstract-wc-legacy-order.php - About 1 hr to fix

          Method update_product has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function update_product( $item, $product, $args ) {
                  wc_deprecated_function( 'WC_Order::update_product', '3.0', 'an interaction with the WC_Order_Item_Product class' );
                  if ( is_numeric( $item ) ) {
                      $item = $this->get_item( $item );
                  }
          Severity: Minor
          Found in includes/legacy/abstract-wc-legacy-order.php - About 1 hr to fix

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

                public function legacy_set_total( $amount, $total_type = 'total' ) {
                    if ( ! in_array( $total_type, array( 'shipping', 'tax', 'shipping_tax', 'total', 'cart_discount', 'cart_discount_tax' ) ) ) {
                        return false;
                    }
            
            
            Severity: Minor
            Found in includes/legacy/abstract-wc-legacy-order.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

            Avoid too many return statements within this method.
            Open

                        return $this->get_shipping_tax();
            Severity: Major
            Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return get_post( $this->get_id() );
              Severity: Major
              Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return $this->get_version();
                Severity: Major
                Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return get_option( 'woocommerce_tax_display_cart' );
                  Severity: Major
                  Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return get_post_status( $this->get_id() );
                    Severity: Major
                    Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return $this->get_currency();
                      Severity: Major
                      Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $this->get_id();
                        Severity: Major
                        Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return $this->{"get_{$key}"}();
                          Severity: Major
                          Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return $this->get_customer_note();
                            Severity: Major
                            Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return 'excl' === get_option( 'woocommerce_tax_display_cart' );
                              Severity: Major
                              Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return $this->get_status();
                                Severity: Major
                                Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return 'excl' === get_option( 'woocommerce_tax_display_cart' );
                                  Severity: Major
                                  Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return $this->get_cart_tax();
                                    Severity: Major
                                    Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                  return $this->get_shipping_total();
                                      Severity: Major
                                      Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return $this->get_total();
                                        Severity: Major
                                        Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                      return $this->get_type();
                                          Severity: Major
                                          Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                        return get_post_meta( $this->get_id(), '_' . $key, true );
                                            Severity: Major
                                            Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return $this->get_discount_tax();
                                              Severity: Major
                                              Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                            return $this->get_customer_id();
                                                Severity: Major
                                                Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                              return $this->get_total_discount();
                                                  Severity: Major
                                                  Found in includes/legacy/abstract-wc-legacy-order.php - About 30 mins to fix

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

                                                        public function update_coupon( $item, $args ) {
                                                            wc_deprecated_function( 'WC_Order::update_coupon', '3.0', 'an interaction with the WC_Order_Item_Coupon class' );
                                                            if ( is_numeric( $item ) ) {
                                                                $item = $this->get_item( $item );
                                                            }
                                                    Severity: Minor
                                                    Found in includes/legacy/abstract-wc-legacy-order.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

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

                                                        public function update_tax( $item, $args ) {
                                                            wc_deprecated_function( 'WC_Order::update_tax', '3.0', 'an interaction with the WC_Order_Item_Tax class' );
                                                            if ( is_numeric( $item ) ) {
                                                                $item = $this->get_item( $item );
                                                            }
                                                    Severity: Major
                                                    Found in includes/legacy/abstract-wc-legacy-order.php and 1 other location - About 3 hrs to fix
                                                    includes/legacy/abstract-wc-legacy-order.php on lines 261..280

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

                                                    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

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

                                                        public function update_fee( $item, $args ) {
                                                            wc_deprecated_function( 'WC_Order::update_fee', '3.0', 'an interaction with the WC_Order_Item_Fee class' );
                                                            if ( is_numeric( $item ) ) {
                                                                $item = $this->get_item( $item );
                                                            }
                                                    Severity: Major
                                                    Found in includes/legacy/abstract-wc-legacy-order.php and 1 other location - About 3 hrs to fix
                                                    includes/legacy/abstract-wc-legacy-order.php on lines 292..311

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

                                                    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