woothemes/woocommerce

View on GitHub
includes/wc-user-functions.php

Summary

Maintainability
F
4 days
Test Coverage

File wc-user-functions.php has 516 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WooCommerce Customer Functions
 *
 * Functions for customers.
Severity: Major
Found in includes/wc-user-functions.php - About 1 day to fix

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

    function wc_customer_has_capability( $allcaps, $caps, $args ) {
        if ( isset( $caps[0] ) ) {
            switch ( $caps[0] ) {
                case 'view_order':
                    $user_id = intval( $args[1] );
    Severity: Minor
    Found in includes/wc-user-functions.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 wc_create_new_customer has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        function wc_create_new_customer( $email, $username = '', $password = '', $args = array() ) {
            if ( empty( $email ) || ! is_email( $email ) ) {
                return new WP_Error( 'registration-error-invalid-email', __( 'Please provide a valid email address.', 'woocommerce' ) );
            }
    
    
    Severity: Minor
    Found in includes/wc-user-functions.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 wc_get_customer_available_downloads has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    function wc_get_customer_available_downloads( $customer_id ) {
        $downloads   = array();
        $_product    = null;
        $order       = null;
        $file_number = 0;
    Severity: Minor
    Found in includes/wc-user-functions.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 wc_modify_map_meta_cap has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) {
        if ( is_multisite() && is_super_admin() ) {
            return $caps;
        }
        switch ( $cap ) {
    Severity: Minor
    Found in includes/wc-user-functions.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 wc_get_customer_available_downloads has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function wc_get_customer_available_downloads( $customer_id ) {
        $downloads   = array();
        $_product    = null;
        $order       = null;
        $file_number = 0;
    Severity: Major
    Found in includes/wc-user-functions.php - About 2 hrs to fix

      Method wc_create_new_customer has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function wc_create_new_customer( $email, $username = '', $password = '', $args = array() ) {
              if ( empty( $email ) || ! is_email( $email ) ) {
                  return new WP_Error( 'registration-error-invalid-email', __( 'Please provide a valid email address.', 'woocommerce' ) );
              }
      
      
      Severity: Minor
      Found in includes/wc-user-functions.php - About 1 hr to fix

        Method wc_create_new_customer_username has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function wc_create_new_customer_username( $email, $new_user_args = array(), $suffix = '' ) {
            $username_parts = array();
        
            if ( isset( $new_user_args['first_name'] ) ) {
                $username_parts[] = sanitize_user( $new_user_args['first_name'], true );
        Severity: Minor
        Found in includes/wc-user-functions.php - About 1 hr to fix

          Method wc_customer_bought_product has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function wc_customer_bought_product( $customer_email, $user_id, $product_id ) {
              global $wpdb;
          
              $result = apply_filters( 'woocommerce_pre_customer_bought_product', null, $customer_email, $user_id, $product_id );
          
          
          Severity: Minor
          Found in includes/wc-user-functions.php - About 1 hr to fix

            Method wc_customer_has_capability has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function wc_customer_has_capability( $allcaps, $caps, $args ) {
                if ( isset( $caps[0] ) ) {
                    switch ( $caps[0] ) {
                        case 'view_order':
                            $user_id = intval( $args[1] );
            Severity: Minor
            Found in includes/wc-user-functions.php - About 1 hr to fix

              Function wc_update_new_customer_past_orders has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

              function wc_update_new_customer_past_orders( $customer_id ) {
                  $linked          = 0;
                  $complete        = 0;
                  $customer        = get_user_by( 'id', absint( $customer_id ) );
                  $customer_orders = wc_get_orders(
              Severity: Minor
              Found in includes/wc-user-functions.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

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

              function wc_customer_bought_product( $customer_email, $user_id, $product_id ) {
                  global $wpdb;
              
                  $result = apply_filters( 'woocommerce_pre_customer_bought_product', null, $customer_email, $user_id, $product_id );
              
              
              Severity: Minor
              Found in includes/wc-user-functions.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

              Method wc_update_new_customer_past_orders has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function wc_update_new_customer_past_orders( $customer_id ) {
                  $linked          = 0;
                  $complete        = 0;
                  $customer        = get_user_by( 'id', absint( $customer_id ) );
                  $customer_orders = wc_get_orders(
              Severity: Minor
              Found in includes/wc-user-functions.php - About 1 hr to fix

                Function wc_create_new_customer_username has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                function wc_create_new_customer_username( $email, $new_user_args = array(), $suffix = '' ) {
                    $username_parts = array();
                
                    if ( isset( $new_user_args['first_name'] ) ) {
                        $username_parts[] = sanitize_user( $new_user_args['first_name'], true );
                Severity: Minor
                Found in includes/wc-user-functions.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

                Method wc_modify_map_meta_cap has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function wc_modify_map_meta_cap( $caps, $cap, $user_id, $args ) {
                    if ( is_multisite() && is_super_admin() ) {
                        return $caps;
                    }
                    switch ( $cap ) {
                Severity: Minor
                Found in includes/wc-user-functions.php - About 1 hr to fix

                  Avoid too many return statements within this method.
                  Open

                          return $customer_id;
                  Severity: Major
                  Found in includes/wc-user-functions.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return $errors;
                    Severity: Major
                    Found in includes/wc-user-functions.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return $customer_id;
                      Severity: Major
                      Found in includes/wc-user-functions.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return new WP_Error( 'registration-error-missing-password', __( 'Please enter an account password.', 'woocommerce' ) );
                        Severity: Major
                        Found in includes/wc-user-functions.php - About 30 mins to fix

                          There are no issues that match your filters.

                          Category
                          Status