woothemes/woocommerce

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

Summary

Maintainability
F
2 wks
Test Coverage

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

<?php
/**
 * WooCommerce Template
 *
 * Functions for the templating system.
Severity: Major
Found in includes/wc-template-functions.php - About 6 days to fix

    Function woocommerce_form_field has a Cognitive Complexity of 78 (exceeds 5 allowed). Consider refactoring.
    Open

        function woocommerce_form_field( $key, $args, $value = null ) {
            $defaults = array(
                'type'              => 'text',
                'label'             => '',
                'description'       => '',
    Severity: Minor
    Found in includes/wc-template-functions.php - About 1 day 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 woocommerce_form_field has 167 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function woocommerce_form_field( $key, $args, $value = null ) {
            $defaults = array(
                'type'              => 'text',
                'label'             => '',
                'description'       => '',
    Severity: Major
    Found in includes/wc-template-functions.php - About 6 hrs to fix

      Function wc_get_product_class has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

      function wc_get_product_class( $class = '', $product = null ) {
          if ( is_null( $product ) && ! empty( $GLOBALS['product'] ) ) {
              // Product was null so pull from global.
              $product = $GLOBALS['product'];
          }
      Severity: Minor
      Found in includes/wc-template-functions.php - About 4 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_formatted_cart_item_data has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

      function wc_get_formatted_cart_item_data( $cart_item, $flat = false ) {
          $item_data = array();
      
          // Variation values are shown only if they are not found in the title as of 3.0.
          // This is because variation titles display the attributes.
      Severity: Minor
      Found in includes/wc-template-functions.php - About 4 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_dropdown_variation_attribute_options has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          function wc_dropdown_variation_attribute_options( $args = array() ) {
              $args = wp_parse_args(
                  apply_filters( 'woocommerce_dropdown_variation_attribute_options_args', $args ),
                  array(
                      'options'          => false,
      Severity: Minor
      Found in includes/wc-template-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

      Method wc_get_product_class has 85 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function wc_get_product_class( $class = '', $product = null ) {
          if ( is_null( $product ) && ! empty( $GLOBALS['product'] ) ) {
              // Product was null so pull from global.
              $product = $GLOBALS['product'];
          }
      Severity: Major
      Found in includes/wc-template-functions.php - About 3 hrs to fix

        Function woocommerce_content has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

            function woocommerce_content() {
        
                if ( is_singular( 'product' ) ) {
        
                    while ( have_posts() ) :
        Severity: Minor
        Found in includes/wc-template-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_display_product_attributes has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        function wc_display_product_attributes( $product ) {
            $product_attributes = array();
        
            // Display weight and dimensions before attribute list.
            $display_dimensions = apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() );
        Severity: Minor
        Found in includes/wc-template-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

        Function wc_query_string_form_fields has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        function wc_query_string_form_fields( $values = null, $exclude = array(), $current_key = '', $return = false ) {
            if ( is_null( $values ) ) {
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended
                $values = $_GET;
            } elseif ( is_string( $values ) ) {
        Severity: Minor
        Found in includes/wc-template-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

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

            function woocommerce_get_loop_display_mode() {
                // Only return products when filtering things.
                if ( wc_get_loop_prop( 'is_search' ) || wc_get_loop_prop( 'is_filtered' ) ) {
                    return 'products';
                }
        Severity: Minor
        Found in includes/wc-template-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_dropdown_variation_attribute_options has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function wc_dropdown_variation_attribute_options( $args = array() ) {
                $args = wp_parse_args(
                    apply_filters( 'woocommerce_dropdown_variation_attribute_options_args', $args ),
                    array(
                        'options'          => false,
        Severity: Major
        Found in includes/wc-template-functions.php - About 2 hrs to fix

          Function wc_display_item_downloads has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              function wc_display_item_downloads( $item, $args = array() ) {
                  $strings = array();
                  $html    = '';
                  $args    = wp_parse_args(
                      $args,
          Severity: Minor
          Found in includes/wc-template-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_display_product_attributes has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function wc_display_product_attributes( $product ) {
              $product_attributes = array();
          
              // Display weight and dimensions before attribute list.
              $display_dimensions = apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() );
          Severity: Minor
          Found in includes/wc-template-functions.php - About 1 hr to fix

            Function wc_product_post_class has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

            function wc_product_post_class( $classes, $class = '', $post_id = 0 ) {
                if ( ! $post_id || ! in_array( get_post_type( $post_id ), array( 'product', 'product_variation' ), true ) ) {
                    return $classes;
                }
            
            
            Severity: Minor
            Found in includes/wc-template-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_product_post_class has 45 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function wc_product_post_class( $classes, $class = '', $post_id = 0 ) {
                if ( ! $post_id || ! in_array( get_post_type( $post_id ), array( 'product', 'product_variation' ), true ) ) {
                    return $classes;
                }
            
            
            Severity: Minor
            Found in includes/wc-template-functions.php - About 1 hr to fix

              Method wc_get_formatted_cart_item_data has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function wc_get_formatted_cart_item_data( $cart_item, $flat = false ) {
                  $item_data = array();
              
                  // Variation values are shown only if they are not found in the title as of 3.0.
                  // This is because variation titles display the attributes.
              Severity: Minor
              Found in includes/wc-template-functions.php - About 1 hr to fix

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

                    function woocommerce_account_content() {
                        global $wp;
                
                        if ( ! empty( $wp->query_vars ) ) {
                            foreach ( $wp->query_vars as $key => $value ) {
                Severity: Minor
                Found in includes/wc-template-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 woocommerce_maybe_show_product_subcategories has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    function woocommerce_maybe_show_product_subcategories( $loop_html = '' ) {
                        if ( wc_get_loop_prop( 'is_shortcode' ) && ! WC_Template_Loader::in_content_filter() ) {
                            return $loop_html;
                        }
                
                
                Severity: Minor
                Found in includes/wc-template-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 woocommerce_catalog_ordering has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    function woocommerce_catalog_ordering() {
                        if ( ! wc_get_loop_prop( 'is_paginated' ) || ! woocommerce_products_will_display() ) {
                            return;
                        }
                        $show_default_orderby    = 'menu_order' === apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby', 'menu_order' ) );
                Severity: Minor
                Found in includes/wc-template-functions.php - About 1 hr to fix

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

                  function wc_query_string_form_fields( $values = null, $exclude = array(), $current_key = '', $return = false ) {
                      if ( is_null( $values ) ) {
                          // phpcs:ignore WordPress.Security.NonceVerification.Recommended
                          $values = $_GET;
                      } elseif ( is_string( $values ) ) {
                  Severity: Minor
                  Found in includes/wc-template-functions.php - About 1 hr to fix

                    Method wc_template_redirect has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function wc_template_redirect() {
                        global $wp_query, $wp;
                    
                        // phpcs:disable WordPress.Security.NonceVerification.Recommended
                        // When default permalinks are enabled, redirect shop page to post type archive url.
                    Severity: Minor
                    Found in includes/wc-template-functions.php - About 1 hr to fix

                      Function woocommerce_product_archive_description has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                          function woocommerce_product_archive_description() {
                              // Don't display the description on search results page.
                              if ( is_search() ) {
                                  return;
                              }
                      Severity: Minor
                      Found in includes/wc-template-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_display_item_downloads has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          function wc_display_item_downloads( $item, $args = array() ) {
                              $strings = array();
                              $html    = '';
                              $args    = wp_parse_args(
                                  $args,
                      Severity: Minor
                      Found in includes/wc-template-functions.php - About 1 hr to fix

                        Function woocommerce_catalog_ordering has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                            function woocommerce_catalog_ordering() {
                                if ( ! wc_get_loop_prop( 'is_paginated' ) || ! woocommerce_products_will_display() ) {
                                    return;
                                }
                                $show_default_orderby    = 'menu_order' === apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby', 'menu_order' ) );
                        Severity: Minor
                        Found in includes/wc-template-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 woocommerce_product_subcategories has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                            function woocommerce_product_subcategories( $args = array() ) {
                                $defaults = array(
                                    'before'        => '',
                                    'after'         => '',
                                    'force_display' => false,
                        Severity: Minor
                        Found in includes/wc-template-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_template_redirect has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function wc_template_redirect() {
                            global $wp_query, $wp;
                        
                            // phpcs:disable WordPress.Security.NonceVerification.Recommended
                            // When default permalinks are enabled, redirect shop page to post type archive url.
                        Severity: Minor
                        Found in includes/wc-template-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_setup_loop has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function wc_setup_loop( $args = array() ) {
                            $default_args = array(
                                'loop'         => 0,
                                'columns'      => wc_get_default_products_per_row(),
                                'name'         => '',
                        Severity: Minor
                        Found in includes/wc-template-functions.php - About 1 hr to fix

                          Method woocommerce_upsell_display has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              function woocommerce_upsell_display( $limit = '-1', $columns = 4, $orderby = 'rand', $order = 'desc' ) {
                                  global $product;
                          
                                  if ( ! $product ) {
                                      return;
                          Severity: Minor
                          Found in includes/wc-template-functions.php - About 1 hr to fix

                            Method wc_get_gallery_image_html has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function wc_get_gallery_image_html( $attachment_id, $main_image = false ) {
                                $flexslider        = (bool) apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) );
                                $gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' );
                                $thumbnail_size    = apply_filters( 'woocommerce_gallery_thumbnail_size', array( $gallery_thumbnail['width'], $gallery_thumbnail['height'] ) );
                                $image_size        = apply_filters( 'woocommerce_gallery_image_size', $flexslider || $main_image ? 'woocommerce_single' : $thumbnail_size );
                            Severity: Minor
                            Found in includes/wc-template-functions.php - About 1 hr to fix

                              Method woocommerce_quantity_input has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  function woocommerce_quantity_input( $args = array(), $product = null, $echo = true ) {
                                      if ( is_null( $product ) ) {
                                          $product = $GLOBALS['product'];
                                      }
                              
                              
                              Severity: Minor
                              Found in includes/wc-template-functions.php - About 1 hr to fix

                                Method wc_body_class has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                function wc_body_class( $classes ) {
                                    $classes = (array) $classes;
                                
                                    if ( is_shop() ) {
                                
                                
                                Severity: Minor
                                Found in includes/wc-template-functions.php - About 1 hr to fix

                                  Method woocommerce_template_loop_add_to_cart has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      function woocommerce_template_loop_add_to_cart( $args = array() ) {
                                          global $product;
                                  
                                          if ( $product ) {
                                              $defaults = array(
                                  Severity: Minor
                                  Found in includes/wc-template-functions.php - About 1 hr to fix

                                    Method wc_get_email_order_items has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        function wc_get_email_order_items( $order, $args = array() ) {
                                            ob_start();
                                    
                                            $defaults = array(
                                                'show_sku'      => false,
                                    Severity: Minor
                                    Found in includes/wc-template-functions.php - About 1 hr to fix

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

                                          function woocommerce_page_title( $echo = true ) {
                                      
                                              if ( is_search() ) {
                                                  /* translators: %s: search query */
                                                  $page_title = sprintf( __( 'Search results: &ldquo;%s&rdquo;', 'woocommerce' ), get_search_query() );
                                      Severity: Minor
                                      Found in includes/wc-template-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_get_product_taxonomy_class has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                      function wc_get_product_taxonomy_class( $term_ids, $taxonomy ) {
                                          $classes = array();
                                      
                                          foreach ( $term_ids as $term_id ) {
                                              $term = get_term( $term_id, $taxonomy );
                                      Severity: Minor
                                      Found in includes/wc-template-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 woocommerce_subcategory_thumbnail has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          function woocommerce_subcategory_thumbnail( $category ) {
                                              $small_thumbnail_size = apply_filters( 'subcategory_archive_thumbnail_size', 'woocommerce_thumbnail' );
                                              $dimensions           = wc_get_image_size( $small_thumbnail_size );
                                              $thumbnail_id         = get_term_meta( $category->term_id, 'thumbnail_id', true );
                                      
                                      
                                      Severity: Minor
                                      Found in includes/wc-template-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_display_item_meta has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                          function wc_display_item_meta( $item, $args = array() ) {
                                              $strings = array();
                                              $html    = '';
                                              $args    = wp_parse_args(
                                                  $args,
                                      Severity: Minor
                                      Found in includes/wc-template-functions.php - About 1 hr to fix

                                        Method woocommerce_content has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                            function woocommerce_content() {
                                        
                                                if ( is_singular( 'product' ) ) {
                                        
                                                    while ( have_posts() ) :
                                        Severity: Minor
                                        Found in includes/wc-template-functions.php - About 1 hr to fix

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

                                              function woocommerce_product_subcategories( $args = array() ) {
                                                  $defaults = array(
                                                      'before'        => '',
                                                      'after'         => '',
                                                      'force_display' => false,
                                          Severity: Minor
                                          Found in includes/wc-template-functions.php - About 1 hr to fix

                                            Consider simplifying this complex logical expression.
                                            Open

                                                if ( is_page( wc_get_page_id( 'checkout' ) ) && wc_get_page_id( 'checkout' ) !== wc_get_page_id( 'cart' ) && WC()->cart->is_empty() && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) && ! is_customize_preview() && apply_filters( 'woocommerce_checkout_redirect_empty_cart', true ) ) {
                                                    wc_add_notice( __( 'Checkout is not available whilst your cart is empty.', 'woocommerce' ), 'notice' );
                                                    wp_safe_redirect( wc_get_cart_url() );
                                                    exit;
                                            
                                            
                                            Severity: Major
                                            Found in includes/wc-template-functions.php - About 1 hr to fix

                                              Function wc_body_class has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function wc_body_class( $classes ) {
                                                  $classes = (array) $classes;
                                              
                                                  if ( is_shop() ) {
                                              
                                              
                                              Severity: Minor
                                              Found in includes/wc-template-functions.php - About 55 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

                                              Function woocommerce_default_product_tabs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  function woocommerce_default_product_tabs( $tabs = array() ) {
                                                      global $product, $post;
                                              
                                                      // Description tab - shows product content.
                                                      if ( $post->post_content ) {
                                              Severity: Minor
                                              Found in includes/wc-template-functions.php - About 45 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

                                              Function woocommerce_quantity_input has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  function woocommerce_quantity_input( $args = array(), $product = null, $echo = true ) {
                                                      if ( is_null( $product ) ) {
                                                          $product = $GLOBALS['product'];
                                                      }
                                              
                                              
                                              Severity: Minor
                                              Found in includes/wc-template-functions.php - About 45 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

                                              Avoid deeply nested control flow statements.
                                              Open

                                                                          if ( empty( $args['placeholder'] ) ) {
                                                                              $args['placeholder'] = $option_text ? $option_text : __( 'Choose an option', 'woocommerce' );
                                                                          }
                                              Severity: Major
                                              Found in includes/wc-template-functions.php - About 45 mins to fix

                                                Function woocommerce_get_product_subcategories has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                Open

                                                    function woocommerce_get_product_subcategories( $parent_id = 0 ) {
                                                        $parent_id          = absint( $parent_id );
                                                        $cache_key          = apply_filters( 'woocommerce_get_product_subcategories_cache_key', 'product-category-hierarchy-' . $parent_id, $parent_id );
                                                        $product_categories = $cache_key ? wp_cache_get( $cache_key, 'product_cat' ) : false;
                                                
                                                
                                                Severity: Minor
                                                Found in includes/wc-template-functions.php - About 35 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

                                                Function wc_display_item_meta has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                Open

                                                    function wc_display_item_meta( $item, $args = array() ) {
                                                        $strings = array();
                                                        $html    = '';
                                                        $args    = wp_parse_args(
                                                            $args,
                                                Severity: Minor
                                                Found in includes/wc-template-functions.php - About 35 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

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

                                                    function woocommerce_taxonomy_archive_description() {
                                                        if ( is_product_taxonomy() && 0 === absint( get_query_var( 'paged' ) ) ) {
                                                            $term = get_queried_object();
                                                
                                                            if ( $term && ! empty( $term->description ) ) {
                                                Severity: Minor
                                                Found in includes/wc-template-functions.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

                                                Similar blocks of code found in 2 locations. Consider refactoring.
                                                Open

                                                                    $field = '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="country_to_state country_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ? $args['placeholder'] : esc_attr__( 'Select a country / region&hellip;', 'woocommerce' ) ) . '"><option value="">' . esc_html__( 'Select a country / region&hellip;', 'woocommerce' ) . '</option>';
                                                Severity: Major
                                                Found in includes/wc-template-functions.php and 1 other location - About 2 hrs to fix
                                                includes/wc-template-functions.php on lines 2783..2783

                                                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 122.

                                                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

                                                Further Reading

                                                Similar blocks of code found in 2 locations. Consider refactoring.
                                                Open

                                                                    $field .= '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" class="state_select ' . esc_attr( implode( ' ', $args['input_class'] ) ) . '" ' . implode( ' ', $custom_attributes ) . ' data-placeholder="' . esc_attr( $args['placeholder'] ? $args['placeholder'] : esc_html__( 'Select an option&hellip;', 'woocommerce' ) ) . '"  data-input-classes="' . esc_attr( implode( ' ', $args['input_class'] ) ) . '">
                                                Severity: Major
                                                Found in includes/wc-template-functions.php and 1 other location - About 2 hrs to fix
                                                includes/wc-template-functions.php on lines 2757..2757

                                                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 122.

                                                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

                                                Further Reading

                                                Similar blocks of code found in 3 locations. Consider refactoring.
                                                Open

                                                        $catalog_orderby_options = apply_filters(
                                                            'woocommerce_catalog_orderby',
                                                            array(
                                                                'menu_order' => __( 'Default sorting', 'woocommerce' ),
                                                                'popularity' => __( 'Sort by popularity', 'woocommerce' ),
                                                Severity: Major
                                                Found in includes/wc-template-functions.php and 2 other locations - About 1 hr to fix
                                                includes/customizer/class-wc-shop-customizer.php on lines 273..283
                                                includes/wc-core-functions.php on lines 1514..1524

                                                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 108.

                                                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

                                                Further Reading

                                                There are no issues that match your filters.

                                                Category
                                                Status