woothemes/woocommerce

View on GitHub
includes/class-wc-order-factory.php

Summary

Maintainability
B
4 hrs
Test Coverage

Function get_order_item has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    public static function get_order_item( $item_id = 0 ) {
        if ( is_numeric( $item_id ) ) {
            $item_type = WC_Data_Store::load( 'order-item' )->get_order_item_type( $item_id );
            $id        = $item_id;
        } elseif ( $item_id instanceof WC_Order_Item ) {
Severity: Minor
Found in includes/class-wc-order-factory.php - About 2 hrs to fix

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_order_item has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function get_order_item( $item_id = 0 ) {
        if ( is_numeric( $item_id ) ) {
            $item_type = WC_Data_Store::load( 'order-item' )->get_order_item_type( $item_id );
            $id        = $item_id;
        } elseif ( $item_id instanceof WC_Order_Item ) {
Severity: Minor
Found in includes/class-wc-order-factory.php - About 1 hr to fix

    Avoid too many return statements within this method.
    Open

                return false;
    Severity: Major
    Found in includes/class-wc-order-factory.php - About 30 mins to fix

      Function get_order_id has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function get_order_id( $order ) {
              global $post;
      
              if ( false === $order && is_a( $post, 'WP_Post' ) && 'shop_order' === get_post_type( $post ) ) {
                  return absint( $post->ID );
      Severity: Minor
      Found in includes/class-wc-order-factory.php - About 25 mins to fix

      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

      There are no issues that match your filters.

      Category
      Status