File class-wc-tax.php
has 667 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Tax calculation and rate finding class.
*
* @package WooCommerce\Classes
WC_Tax
has 46 functions (exceeds 20 allowed). Consider refactoring. Open
class WC_Tax {
/**
* Precision.
*
Function get_shipping_tax_rates
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public static function get_shipping_tax_rates( $tax_class = null, $customer = null ) {
// See if we have an explicitly set shipping tax class.
$shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );
if ( 'inherit' !== $shipping_tax_class ) {
- 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 calc_exclusive_tax
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public static function calc_exclusive_tax( $price, $rates ) {
$taxes = array();
if ( ! empty( $rates ) ) {
foreach ( $rates as $key => $rate ) {
- 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_matched_tax_rates
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function get_matched_tax_rates( $country, $state, $postcode, $city, $tax_class ) {
global $wpdb;
// Query criteria - these will be ANDed.
$criteria = array();
Method get_shipping_tax_rates
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function get_shipping_tax_rates( $tax_class = null, $customer = null ) {
// See if we have an explicitly set shipping tax class.
$shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );
if ( 'inherit' !== $shipping_tax_class ) {
Function sort_rates_callback
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private static function sort_rates_callback( $rate1, $rate2 ) {
if ( $rate1->tax_rate_priority !== $rate2->tax_rate_priority ) {
return $rate1->tax_rate_priority < $rate2->tax_rate_priority ? -1 : 1; // ASC.
}
- 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 calc_exclusive_tax
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function calc_exclusive_tax( $price, $rates ) {
$taxes = array();
if ( ! empty( $rates ) ) {
foreach ( $rates as $key => $rate ) {
Method create_tax_class
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function create_tax_class( $name, $slug = '' ) {
global $wpdb;
if ( empty( $name ) ) {
return new WP_Error( 'tax_class_invalid_name', __( 'Tax class requires a valid name', 'woocommerce' ) );
Method sort_rates_callback
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function sort_rates_callback( $rate1, $rate2 ) {
if ( $rate1->tax_rate_priority !== $rate2->tax_rate_priority ) {
return $rate1->tax_rate_priority < $rate2->tax_rate_priority ? -1 : 1; // ASC.
}
Function get_matched_tax_rates
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function get_matched_tax_rates( $country, $state, $postcode, $city, $tax_class ) {
global $wpdb;
// Query criteria - these will be ANDed.
$criteria = 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 calc_inclusive_tax
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function calc_inclusive_tax( $price, $rates ) {
$taxes = array();
$compound_rates = array();
$regular_rates = array();
Function get_rates_for_tax_class
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function get_rates_for_tax_class( $tax_class ) {
global $wpdb;
$tax_class = self::format_tax_rate_class( $tax_class );
- 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_matched_tax_rates
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function get_matched_tax_rates( $country, $state, $postcode, $city, $tax_class ) {
Function prepare_tax_rate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function prepare_tax_rate( $tax_rate ) {
foreach ( $tax_rate as $key => $value ) {
if ( method_exists( __CLASS__, 'format_' . $key ) ) {
if ( 'tax_rate_state' === $key ) {
$tax_rate[ $key ] = call_user_func( array( __CLASS__, 'format_' . $key ), sanitize_key( $value ) );
- 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
Avoid too many return
statements within this method. Open
return $rate1->city_count < $rate2->city_count ? 1 : -1;
Avoid too many return
statements within this method. Open
return $rate1->tax_rate_id < $rate2->tax_rate_id ? -1 : 1;
Avoid too many return
statements within this method. Open
return -1;
Avoid too many return
statements within this method. Open
return $rate1->postcode_count < $rate2->postcode_count ? 1 : -1;
Avoid too many return
statements within this method. Open
return strcmp( $rate1->tax_rate_state, $rate2->tax_rate_state ) > 0 ? 1 : -1;
Avoid too many return
statements within this method. Open
return 1;
Avoid too many return
statements within this method. Open
return array(
'name' => $name,
'slug' => $slug,
);
Function find_shipping_rates
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function find_shipping_rates( $args = array() ) {
$rates = self::find_rates( $args );
$shipping_rates = array();
if ( is_array( $rates ) ) {
- 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 calc_inclusive_tax
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function calc_inclusive_tax( $price, $rates ) {
$taxes = array();
$compound_rates = array();
$regular_rates = 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"