woothemes/woocommerce

View on GitHub
includes/class-wc-cart-session.php

Summary

Maintainability
D
2 days
Test Coverage

Function populate_cart_from_order has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

    private function populate_cart_from_order( $order_id, $cart ) {
        $order = wc_get_order( $order_id );

        if ( ! $order->get_id() || ! $order->has_status( apply_filters( 'woocommerce_valid_order_statuses_for_order_again', array( 'completed' ) ) ) || ! current_user_can( 'order_again', $order->get_id() ) ) {
            return;
Severity: Minor
Found in includes/class-wc-cart-session.php - About 3 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

Function get_cart_from_session has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    public function get_cart_from_session() {
        do_action( 'woocommerce_load_cart_from_session' );
        $this->cart->set_totals( WC()->session->get( 'cart_totals', null ) );
        $this->cart->set_applied_coupons( WC()->session->get( 'applied_coupons', array() ) );
        $this->cart->set_coupon_discount_totals( WC()->session->get( 'coupon_discount_totals', array() ) );
Severity: Minor
Found in includes/class-wc-cart-session.php - About 3 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 populate_cart_from_order has 77 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function populate_cart_from_order( $order_id, $cart ) {
        $order = wc_get_order( $order_id );

        if ( ! $order->get_id() || ! $order->has_status( apply_filters( 'woocommerce_valid_order_statuses_for_order_again', array( 'completed' ) ) ) || ! current_user_can( 'order_again', $order->get_id() ) ) {
            return;
Severity: Major
Found in includes/class-wc-cart-session.php - About 3 hrs to fix

    Method get_cart_from_session has 69 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get_cart_from_session() {
            do_action( 'woocommerce_load_cart_from_session' );
            $this->cart->set_totals( WC()->session->get( 'cart_totals', null ) );
            $this->cart->set_applied_coupons( WC()->session->get( 'applied_coupons', array() ) );
            $this->cart->set_coupon_discount_totals( WC()->session->get( 'coupon_discount_totals', array() ) );
    Severity: Major
    Found in includes/class-wc-cart-session.php - About 2 hrs to fix

      File class-wc-cart-session.php has 263 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      /**
       * Cart session handling class.
       *
       * @package WooCommerce\Classes
      Severity: Minor
      Found in includes/class-wc-cart-session.php - About 2 hrs to fix

        Function set_cart_cookies has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            private function set_cart_cookies( $set = true ) {
                if ( $set ) {
                    $setcookies = array(
                        'woocommerce_items_in_cart' => '1',
                        'woocommerce_cart_hash'     => WC()->cart->get_cart_hash(),
        Severity: Minor
        Found in includes/class-wc-cart-session.php - About 1 hr 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