File wc-attribute-functions.php
has 394 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* WooCommerce Attribute Functions
*
* @package WooCommerce\Functions
Function wc_create_attribute
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
function wc_create_attribute( $args ) {
global $wpdb;
$args = wp_unslash( $args );
$id = ! empty( $args['id'] ) ? intval( $args['id'] ) : 0;
- 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_create_attribute
has 100 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wc_create_attribute( $args ) {
global $wpdb;
$args = wp_unslash( $args );
$id = ! empty( $args['id'] ) ? intval( $args['id'] ) : 0;
Method wc_check_if_attribute_name_is_reserved
has 77 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wc_check_if_attribute_name_is_reserved( $attribute_name ) {
// Forbidden attribute names.
$reserved_terms = array(
'attachment',
'attachment_id',
Function wc_attribute_label
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function wc_attribute_label( $name, $product = '' ) {
if ( taxonomy_is_product_attribute( $name ) ) {
$slug = wc_attribute_taxonomy_slug( $name );
$all_labels = wc_get_attribute_taxonomy_labels();
$label = isset( $all_labels[ $slug ] ) ? $all_labels[ $slug ] : $slug;
- 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_delete_attribute
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wc_delete_attribute( $id ) {
global $wpdb;
$name = $wpdb->get_var(
$wpdb->prepare(
Function wc_delete_attribute
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function wc_delete_attribute( $id ) {
global $wpdb;
$name = $wpdb->get_var(
$wpdb->prepare(
- 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 too many return
statements within this method. Open
return $id;
Avoid too many return
statements within this method. Open
return new WP_Error( 'cannot_create_attribute', $results->get_error_message(), array( 'status' => 400 ) );
Avoid too many return
statements within this method. Open
return new WP_Error( 'cannot_update_attribute', __( 'Could not update the attribute.', 'woocommerce' ), array( 'status' => 400 ) );