woothemes/woocommerce

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

Summary

Maintainability
F
3 days
Test Coverage

WC_Coupon has 62 functions (exceeds 20 allowed). Consider refactoring.
Open

class WC_Coupon extends WC_Legacy_Coupon {

    /**
     * Data array, with defaults.
     *
Severity: Major
Found in includes/class-wc-coupon.php - About 1 day to fix

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

    <?php
    /**
     * WooCommerce coupons.
     *
     * The WooCommerce coupons class gets coupon data from storage and checks coupon validity.
    Severity: Minor
    Found in includes/class-wc-coupon.php - About 7 hrs to fix

      Function get_coupon_error has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
      Open

          public function get_coupon_error( $err_code ) {
              switch ( $err_code ) {
                  case self::E_WC_COUPON_INVALID_FILTERED:
                      $err = __( 'Coupon is not valid.', 'woocommerce' );
                      break;
      Severity: Minor
      Found in includes/class-wc-coupon.php - About 5 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_coupon_error has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function get_coupon_error( $err_code ) {
              switch ( $err_code ) {
                  case self::E_WC_COUPON_INVALID_FILTERED:
                      $err = __( 'Coupon is not valid.', 'woocommerce' );
                      break;
      Severity: Major
      Found in includes/class-wc-coupon.php - About 3 hrs to fix

        Function read_manual_coupon has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public function read_manual_coupon( $code, $coupon ) {
                foreach ( $coupon as $key => $value ) {
                    switch ( $key ) {
                        case 'excluded_product_ids':
                        case 'exclude_product_ids':
        Severity: Minor
        Found in includes/class-wc-coupon.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 read_manual_coupon has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function read_manual_coupon( $code, $coupon ) {
                foreach ( $coupon as $key => $value ) {
                    switch ( $key ) {
                        case 'excluded_product_ids':
                        case 'exclude_product_ids':
        Severity: Minor
        Found in includes/class-wc-coupon.php - About 1 hr to fix

          Function __construct has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public function __construct( $data = '' ) {
                  parent::__construct( $data );
          
                  // If we already have a coupon object, read it again.
                  if ( $data instanceof WC_Coupon ) {
          Severity: Minor
          Found in includes/class-wc-coupon.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 is_valid_for_product has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function is_valid_for_product( $product, $values = array() ) {
                  if ( ! $this->is_type( wc_get_product_coupon_types() ) ) {
                      return apply_filters( 'woocommerce_coupon_is_valid_for_product', false, $product, $this, $values );
                  }
          
          
          Severity: Minor
          Found in includes/class-wc-coupon.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_discount_amount has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function get_discount_amount( $discounting_amount, $cart_item = null, $single = false ) {
                  $discount      = 0;
                  $cart_item_qty = is_null( $cart_item ) ? 1 : $cart_item['quantity'];
          
                  if ( $this->is_type( array( 'percent' ) ) ) {
          Severity: Minor
          Found in includes/class-wc-coupon.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

          There are no issues that match your filters.

          Category
          Status