File abstract-wc-legacy-order.php
has 435 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
WC_Abstract_Legacy_Order
has 35 functions (exceeds 20 allowed). Consider refactoring. Open
abstract class WC_Abstract_Legacy_Order extends WC_Data {
/**
* Add coupon code to the order.
* @param string|array $code
Function __get
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public function __get( $key ) {
wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '3.0' );
if ( 'completed_date' === $key ) {
return $this->get_date_completed() ? gmdate( 'Y-m-d H:i:s', $this->get_date_completed()->getOffsetTimestamp() ) : '';
- 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 update_product
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function update_product( $item, $product, $args ) {
wc_deprecated_function( 'WC_Order::update_product', '3.0', 'an interaction with the WC_Order_Item_Product class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $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 __get
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __get( $key ) {
wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '3.0' );
if ( 'completed_date' === $key ) {
return $this->get_date_completed() ? gmdate( 'Y-m-d H:i:s', $this->get_date_completed()->getOffsetTimestamp() ) : '';
Method legacy_set_total
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function legacy_set_total( $amount, $total_type = 'total' ) {
if ( ! in_array( $total_type, array( 'shipping', 'tax', 'shipping_tax', 'total', 'cart_discount', 'cart_discount_tax' ) ) ) {
return false;
}
Method update_product
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function update_product( $item, $product, $args ) {
wc_deprecated_function( 'WC_Order::update_product', '3.0', 'an interaction with the WC_Order_Item_Product class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $item );
}
Function legacy_set_total
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function legacy_set_total( $amount, $total_type = 'total' ) {
if ( ! in_array( $total_type, array( 'shipping', 'tax', 'shipping_tax', 'total', 'cart_discount', 'cart_discount_tax' ) ) ) {
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
Avoid too many return
statements within this method. Open
return $this->get_shipping_tax();
Avoid too many return
statements within this method. Open
return get_post( $this->get_id() );
Avoid too many return
statements within this method. Open
return $this->get_version();
Avoid too many return
statements within this method. Open
return get_option( 'woocommerce_tax_display_cart' );
Avoid too many return
statements within this method. Open
return get_post_status( $this->get_id() );
Avoid too many return
statements within this method. Open
return $this->get_currency();
Avoid too many return
statements within this method. Open
return $this->get_id();
Avoid too many return
statements within this method. Open
return $this->{"get_{$key}"}();
Avoid too many return
statements within this method. Open
return $this->get_customer_note();
Avoid too many return
statements within this method. Open
return 'excl' === get_option( 'woocommerce_tax_display_cart' );
Avoid too many return
statements within this method. Open
return $this->get_status();
Avoid too many return
statements within this method. Open
return 'excl' === get_option( 'woocommerce_tax_display_cart' );
Avoid too many return
statements within this method. Open
return $this->get_cart_tax();
Avoid too many return
statements within this method. Open
return $this->get_shipping_total();
Avoid too many return
statements within this method. Open
return $this->get_total();
Avoid too many return
statements within this method. Open
return $this->get_type();
Avoid too many return
statements within this method. Open
return get_post_meta( $this->get_id(), '_' . $key, true );
Avoid too many return
statements within this method. Open
return $this->get_discount_tax();
Avoid too many return
statements within this method. Open
return $this->get_customer_id();
Avoid too many return
statements within this method. Open
return $this->get_total_discount();
Function update_coupon
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function update_coupon( $item, $args ) {
wc_deprecated_function( 'WC_Order::update_coupon', '3.0', 'an interaction with the WC_Order_Item_Coupon class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $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
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function update_tax( $item, $args ) {
wc_deprecated_function( 'WC_Order::update_tax', '3.0', 'an interaction with the WC_Order_Item_Tax class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $item );
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 160.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
public function update_fee( $item, $args ) {
wc_deprecated_function( 'WC_Order::update_fee', '3.0', 'an interaction with the WC_Order_Item_Fee class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $item );
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 160.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76