File class-wc-cart-totals.php
has 442 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Cart totals calculation class.
*
* Methods are protected and class is final to keep this as an internal API.
Function get_fees_from_cart
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
protected function get_fees_from_cart() {
$this->fees = array();
$this->cart->calculate_fees();
$fee_running_total = 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
WC_Cart_Totals
has 29 functions (exceeds 20 allowed). Consider refactoring. Open
final class WC_Cart_Totals {
use WC_Item_Totals;
/**
* Reference to cart object.
Function calculate_item_subtotals
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
protected function calculate_item_subtotals() {
$merged_subtotal_taxes = array(); // Taxes indexed by tax rate ID for storage later.
$adjust_non_base_location_prices = apply_filters( 'woocommerce_adjust_non_base_location_prices', true );
$is_customer_vat_exempt = $this->cart->get_customer()->get_is_vat_exempt();
- 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_discounts
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
protected function calculate_discounts() {
$this->get_coupons_from_cart();
$discounts = new WC_Discounts( $this->cart );
- 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_fees_from_cart
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function get_fees_from_cart() {
$this->fees = array();
$this->cart->calculate_fees();
$fee_running_total = 0;
Method calculate_discounts
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function calculate_discounts() {
$this->get_coupons_from_cart();
$discounts = new WC_Discounts( $this->cart );
Method calculate_item_subtotals
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function calculate_item_subtotals() {
$merged_subtotal_taxes = array(); // Taxes indexed by tax rate ID for storage later.
$adjust_non_base_location_prices = apply_filters( 'woocommerce_adjust_non_base_location_prices', true );
$is_customer_vat_exempt = $this->cart->get_customer()->get_is_vat_exempt();
Method calculate_item_totals
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function calculate_item_totals() {
$this->get_items_from_cart();
$this->calculate_item_subtotals();
$this->calculate_discounts();
Function get_merged_taxes
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function get_merged_taxes( $in_cents = false, $types = array( 'items', 'fees', 'shipping' ) ) {
$items = array();
$taxes = array();
if ( is_string( $types ) ) {
- 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_item_totals
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function calculate_item_totals() {
$this->get_items_from_cart();
$this->calculate_item_subtotals();
$this->calculate_discounts();
- 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_class_costs
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function get_tax_class_costs() {
$item_tax_classes = wp_list_pluck( $this->items, 'tax_class' );
$shipping_tax_classes = wp_list_pluck( $this->shipping, 'tax_class' );
$fee_tax_classes = wp_list_pluck( $this->fees, 'tax_class' );
$costs = array_fill_keys( $item_tax_classes + $shipping_tax_classes + $fee_tax_classes, 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_coupons_from_cart
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function get_coupons_from_cart() {
$this->coupons = $this->cart->get_coupons();
foreach ( $this->coupons as $coupon ) {
switch ( $coupon->get_discount_type() ) {
- 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 combine_item_taxes
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function combine_item_taxes( $item_taxes ) {
$merged_taxes = array();
foreach ( $item_taxes as $taxes ) {
foreach ( $taxes as $tax_id => $tax_amount ) {
if ( ! isset( $merged_taxes[ $tax_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_item_costs_by_tax_class
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function get_item_costs_by_tax_class() {
$tax_classes = array(
'non-taxable' => 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 sort_coupons_callback
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function sort_coupons_callback( $a, $b ) {
if ( $a->sort === $b->sort ) {
if ( $a->get_limit_usage_to_x_items() === $b->get_limit_usage_to_x_items() ) {
if ( $a->get_amount() === $b->get_amount() ) {
return $b->get_id() - $a->get_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"