WC_Coupon
has 62 functions (exceeds 20 allowed). Consider refactoring. Open
class WC_Coupon extends WC_Legacy_Coupon {
/**
* Data array, with defaults.
*
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.
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;
- Read upRead up
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;
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':
- Read upRead up
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':
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 ) {
- Read upRead up
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 );
}
- Read upRead up
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' ) ) ) {
- Read upRead up
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"