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.
WC_Cart
has 110 functions (exceeds 20 allowed). Consider refactoring. Open
class WC_Cart extends WC_Legacy_Cart {
/**
* Contains an array of cart items.
*
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 );
- 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 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 );
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;
}
- 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 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() ) {
- 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
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;
}
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() ) {
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() ) {
- 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 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;
- 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_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();
- 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_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' );
- 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_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();
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;
}
- 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 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;
- 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_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 ) {
- 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_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 ) ) {
- 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 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() ) {
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return apply_filters( 'woocommerce_cart_ready_to_calc_shipping', true );
Avoid too many return
statements within this method. Open
return false;
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 ) {
- 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 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;
- 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 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();
- 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_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 ) ) {
- 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"