woothemes/woocommerce

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

Summary

Maintainability
D
2 days
Test Coverage

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

<?php
/**
 * WooCommerce Attribute Functions
 *
 * @package WooCommerce\Functions
Severity: Minor
Found in includes/wc-attribute-functions.php - About 5 hrs to fix

    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;
    Severity: Minor
    Found in includes/wc-attribute-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

    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;
    Severity: Major
    Found in includes/wc-attribute-functions.php - About 4 hrs to fix

      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',
      Severity: Major
      Found in includes/wc-attribute-functions.php - About 3 hrs to fix

        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;
        Severity: Minor
        Found in includes/wc-attribute-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_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(
        Severity: Minor
        Found in includes/wc-attribute-functions.php - About 1 hr to fix

          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(
          Severity: Minor
          Found in includes/wc-attribute-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

          Avoid too many return statements within this method.
          Open

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

            Avoid too many return statements within this method.
            Open

                        return new WP_Error( 'cannot_create_attribute', $results->get_error_message(), array( 'status' => 400 ) );
            Severity: Major
            Found in includes/wc-attribute-functions.php - About 30 mins to fix

              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 ) );
              Severity: Major
              Found in includes/wc-attribute-functions.php - About 30 mins to fix

                There are no issues that match your filters.

                Category
                Status