File wc-template-functions.php
has 2201 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* WooCommerce Template
*
* Functions for the templating system.
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' => '',
- 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 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' => '',
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'];
}
- 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 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.
- 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 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,
- 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 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'];
}
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() ) :
- 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 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() );
- 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 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 ) ) {
- 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 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';
}
- 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 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,
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,
- 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 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() );
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;
}
- 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 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;
}
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.
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 ) {
- 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 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;
}
- 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 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' ) );
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 ) ) {
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.
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;
}
- 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 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,
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' ) );
- 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 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,
- 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 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.
- 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 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' => '',
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;
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 );
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'];
}
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() ) {
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(
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,
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: “%s”', 'woocommerce' ), get_search_query() );
- 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 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 );
- 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 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 );
- 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 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,
Method woocommerce_content
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function woocommerce_content() {
if ( is_singular( 'product' ) ) {
while ( have_posts() ) :
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,
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;
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() ) {
- 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 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 ) {
- 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 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'];
}
- 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 deeply nested control flow statements. Open
if ( empty( $args['placeholder'] ) ) {
$args['placeholder'] = $option_text ? $option_text : __( 'Choose an option', 'woocommerce' );
}
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;
- 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 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,
- 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 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 ) ) {
- 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
$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…', 'woocommerce' ) ) . '"><option value="">' . esc_html__( 'Select a country / region…', 'woocommerce' ) . '</option>';
- 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 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
- 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
$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…', 'woocommerce' ) ) . '" data-input-classes="' . esc_attr( implode( ' ', $args['input_class'] ) ) . '">
- 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 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
- 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 3 locations. Consider refactoring. Open
$catalog_orderby_options = apply_filters(
'woocommerce_catalog_orderby',
array(
'menu_order' => __( 'Default sorting', 'woocommerce' ),
'popularity' => __( 'Sort by popularity', 'woocommerce' ),
- 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 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
- 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