File class-wc-discounts.php
has 510 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Discount calculation
*
* @package WooCommerce\Classes
WC_Discounts
has 37 functions (exceeds 20 allowed). Consider refactoring. Open
class WC_Discounts {
/**
* Reference to cart or order object.
*
Function validate_coupon_excluded_product_categories
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function validate_coupon_excluded_product_categories( $coupon ) {
if ( count( $coupon->get_excluded_product_categories() ) > 0 ) {
$categories = array();
foreach ( $this->get_items_to_validate() as $item ) {
- 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 validate_coupon_product_categories
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
protected function validate_coupon_product_categories( $coupon ) {
if ( count( $coupon->get_product_categories() ) > 0 ) {
$valid = false;
foreach ( $this->get_items_to_validate() as $item ) {
- 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 validate_coupon_user_usage_limit
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected function validate_coupon_user_usage_limit( $coupon, $user_id = 0 ) {
if ( empty( $user_id ) ) {
if ( $this->object instanceof WC_Order ) {
$user_id = $this->object->get_customer_id();
} else {
- 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 apply_coupon_percent
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function apply_coupon_percent( $coupon, $items_to_apply ) {
$total_discount = 0;
$cart_total = 0;
$limit_usage_qty = 0;
$applied_count = 0;
Function validate_coupon_product_ids
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
protected function validate_coupon_product_ids( $coupon ) {
if ( count( $coupon->get_product_ids() ) > 0 ) {
$valid = false;
foreach ( $this->get_items_to_validate() as $item ) {
- 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 validate_coupon_usage_limit
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function validate_coupon_usage_limit( $coupon ) {
if ( ! $coupon->get_usage_limit() ) {
return true;
}
$usage_count = $coupon->get_usage_count();
Function validate_coupon_excluded_items
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function validate_coupon_excluded_items( $coupon ) {
$items = $this->get_items_to_validate();
if ( ! empty( $items ) && $coupon->is_type( wc_get_product_coupon_types() ) ) {
$valid = false;
- 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 apply_coupon_fixed_cart
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function apply_coupon_fixed_cart( $coupon, $items_to_apply, $amount = null ) {
$total_discount = 0;
$amount = $amount ? $amount : wc_add_number_precision( $coupon->get_amount() );
$items_to_apply = array_filter( $items_to_apply, array( $this, 'filter_products_with_price' ) );
$item_count = array_sum( wp_list_pluck( $items_to_apply, 'quantity' ) );
- 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 apply_coupon_remainder
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function apply_coupon_remainder( $coupon, $items_to_apply, $amount ) {
$total_discount = 0;
foreach ( $items_to_apply as $item ) {
for ( $i = 0; $i < $item->quantity; $i ++ ) {
- 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 validate_coupon_sale_items
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function validate_coupon_sale_items( $coupon ) {
if ( $coupon->get_exclude_sale_items() ) {
$valid = true;
foreach ( $this->get_items_to_validate() as $item ) {
- 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 validate_coupon_excluded_product_ids
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function validate_coupon_excluded_product_ids( $coupon ) {
// Exclude Products.
if ( count( $coupon->get_excluded_product_ids() ) > 0 ) {
$products = array();
- 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 apply_coupon_fixed_product
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function apply_coupon_fixed_product( $coupon, $items_to_apply, $amount = null ) {
$total_discount = 0;
$amount = $amount ? $amount : wc_add_number_precision( $coupon->get_amount() );
$limit_usage_qty = 0;
$applied_count = 0;
Method apply_coupon
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function apply_coupon( $coupon, $validate = true ) {
if ( ! is_a( $coupon, 'WC_Coupon' ) ) {
return new WP_Error( 'invalid_coupon', __( 'Invalid coupon', 'woocommerce' ) );
}
Function get_items_to_apply_coupon
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function get_items_to_apply_coupon( $coupon ) {
$items_to_apply = array();
foreach ( $this->get_items_to_validate() as $item ) {
$item_to_apply = clone $item; // Clone the item so changes to this item do not affect the originals.
- 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 apply_coupon_percent
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function apply_coupon_percent( $coupon, $items_to_apply ) {
$total_discount = 0;
$cart_total = 0;
$limit_usage_qty = 0;
$applied_count = 0;
- 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 validate_coupon_usage_limit
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function validate_coupon_usage_limit( $coupon ) {
if ( ! $coupon->get_usage_limit() ) {
return true;
}
$usage_count = $coupon->get_usage_count();
- 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 apply_coupon
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function apply_coupon( $coupon, $validate = true ) {
if ( ! is_a( $coupon, 'WC_Coupon' ) ) {
return new WP_Error( 'invalid_coupon', __( 'Invalid coupon', 'woocommerce' ) );
}
- 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 apply_coupon_fixed_product
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function apply_coupon_fixed_product( $coupon, $items_to_apply, $amount = null ) {
$total_discount = 0;
$amount = $amount ? $amount : wc_add_number_precision( $coupon->get_amount() );
$limit_usage_qty = 0;
$applied_count = 0;
- 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"