woothemes/woocommerce

View on GitHub
includes/class-wc-comments.php

Summary

Maintainability
C
1 day
Test Coverage

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

    public static function wp_count_comments( $stats, $post_id ) {
        global $wpdb;

        if ( 0 === $post_id ) {
            $stats = get_transient( 'wc_count_comments' );
Severity: Minor
Found in includes/class-wc-comments.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

WC_Comments has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

class WC_Comments {

    /**
     * Hook in methods.
     */
Severity: Minor
Found in includes/class-wc-comments.php - About 2 hrs to fix

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

        public static function wp_count_comments( $stats, $post_id ) {
            global $wpdb;
    
            if ( 0 === $post_id ) {
                $stats = get_transient( 'wc_count_comments' );
    Severity: Minor
    Found in includes/class-wc-comments.php - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

              if ( ! is_admin() && isset( $_POST['comment_post_ID'], $_POST['rating'], $comment_data['comment_type'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) && empty( $_POST['rating'] ) && self::is_default_comment_type( $comment_data['comment_type'] ) && wc_review_ratings_enabled() && wc_review_ratings_required() ) { // WPCS: input var ok, CSRF ok.
                  wp_die( esc_html__( 'Please rate the product.', 'woocommerce' ) );
                  exit;
              }
      Severity: Major
      Found in includes/class-wc-comments.php - About 1 hr to fix

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

            public static function add_comment_rating( $comment_id ) {
                if ( isset( $_POST['rating'], $_POST['comment_post_ID'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) ) { // WPCS: input var ok, CSRF ok.
                    if ( ! $_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0 ) { // WPCS: input var ok, CSRF ok, sanitization ok.
                        return;
                    }
        Severity: Minor
        Found in includes/class-wc-comments.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

        There are no issues that match your filters.

        Category
        Status