WP-API/WP-API

View on GitHub
lib/endpoints/class-wp-rest-comments-controller.php

Summary

Maintainability
F
1 wk
Test Coverage

File class-wp-rest-comments-controller.php has 928 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * Access comments
 */
Severity: Major
Found in lib/endpoints/class-wp-rest-comments-controller.php - About 2 days to fix

    Method get_item_schema has 148 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get_item_schema() {
            $schema = array(
                '$schema'              => 'http://json-schema.org/draft-04/schema#',
                'title'                => 'comment',
                'type'                 => 'object',
    Severity: Major
    Found in lib/endpoints/class-wp-rest-comments-controller.php - About 5 hrs to fix

      Method get_collection_params has 116 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function get_collection_params() {
              $query_params = parent::get_collection_params();
      
              $query_params['context']['default'] = 'view';
      
      
      Severity: Major
      Found in lib/endpoints/class-wp-rest-comments-controller.php - About 4 hrs to fix

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

            public function get_items_permissions_check( $request ) {
        
                if ( ! empty( $request['post'] ) ) {
                    foreach ( (array) $request['post'] as $post_id ) {
                        $post = $this->get_post( $post_id );
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-comments-controller.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 create_item has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
        Open

            public function create_item( $request ) {
                if ( ! empty( $request['id'] ) ) {
                    return new WP_Error( 'rest_comment_exists', __( 'Cannot create existing comment.' ), array( 'status' => 400 ) );
                }
        
        
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-comments-controller.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 create_item has 83 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function create_item( $request ) {
                if ( ! empty( $request['id'] ) ) {
                    return new WP_Error( 'rest_comment_exists', __( 'Cannot create existing comment.' ), array( 'status' => 400 ) );
                }
        
        
        Severity: Major
        Found in lib/endpoints/class-wp-rest-comments-controller.php - About 3 hrs to fix

          Method get_items has 81 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function get_items( $request ) {
          
                  // Retrieve the list of registered collection query parameters.
                  $registered = $this->get_collection_params();
          
          
          Severity: Major
          Found in lib/endpoints/class-wp-rest-comments-controller.php - About 3 hrs to fix

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

                protected function prepare_item_for_database( $request ) {
                    $prepared_comment = array();
            
                    /**
                     * Allow the comment_content to be set via the 'content' or
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-comments-controller.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 get_items has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get_items( $request ) {
            
                    // Retrieve the list of registered collection query parameters.
                    $registered = $this->get_collection_params();
            
            
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-comments-controller.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

            WP_REST_Comments_Controller has 23 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class WP_REST_Comments_Controller extends WP_REST_Controller {
            
                /**
                 * Instance of a comment meta fields object.
                 *
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-comments-controller.php - About 2 hrs to fix

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

                  public function update_item( $request ) {
                      $id = (int) $request['id'];
              
                      $comment = get_comment( $id );
                      if ( empty( $comment ) ) {
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-comments-controller.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 prepare_item_for_database has 56 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function prepare_item_for_database( $request ) {
                      $prepared_comment = array();
              
                      /**
                       * Allow the comment_content to be set via the 'content' or
              Severity: Major
              Found in lib/endpoints/class-wp-rest-comments-controller.php - About 2 hrs to fix

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

                    public function create_item_permissions_check( $request ) {
                
                        if ( ! is_user_logged_in() && get_option( 'comment_registration' ) ) {
                            return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
                        }
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-comments-controller.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 update_item has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function update_item( $request ) {
                        $id = (int) $request['id'];
                
                        $comment = get_comment( $id );
                        if ( empty( $comment ) ) {
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                  Method register_routes has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function register_routes() {
                  
                          register_rest_route( $this->namespace, '/' . $this->rest_base, array(
                              array(
                                  'methods'   => WP_REST_Server::READABLE,
                  Severity: Minor
                  Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                    Method prepare_links has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        protected function prepare_links( $comment ) {
                            $links = array(
                                'self' => array(
                                    'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID ) ),
                                ),
                    Severity: Minor
                    Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                      Method prepare_item_for_response has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function prepare_item_for_response( $comment, $request ) {
                              $data = array(
                                  'id'                 => (int) $comment->comment_ID,
                                  'post'               => (int) $comment->comment_post_ID,
                                  'parent'             => (int) $comment->comment_parent,
                      Severity: Minor
                      Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                        Method get_items_permissions_check has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function get_items_permissions_check( $request ) {
                        
                                if ( ! empty( $request['post'] ) ) {
                                    foreach ( (array) $request['post'] as $post_id ) {
                                        $post = $this->get_post( $post_id );
                        Severity: Minor
                        Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                          Method handle_status_param has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              protected function handle_status_param( $new_status, $comment ) {
                                  $old_status = wp_get_comment_status( $comment->comment_ID );
                          
                                  if ( $new_status === $old_status ) {
                                      return false;
                          Severity: Minor
                          Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                            Method create_item_permissions_check has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function create_item_permissions_check( $request ) {
                            
                                    if ( ! is_user_logged_in() && get_option( 'comment_registration' ) ) {
                                        return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
                                    }
                            Severity: Minor
                            Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

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

                                  protected function check_read_permission( $comment ) {
                                      if ( ! empty( $comment->comment_post_ID ) ) {
                                          $post = get_post( $comment->comment_post_ID );
                                          if ( $post ) {
                                              if ( $this->check_read_post_permission( $post ) && 1 === (int) $comment->comment_approved ) {
                              Severity: Minor
                              Found in lib/endpoints/class-wp-rest-comments-controller.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 handle_status_param has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  protected function handle_status_param( $new_status, $comment ) {
                                      $old_status = wp_get_comment_status( $comment->comment_ID );
                              
                                      if ( $new_status === $old_status ) {
                                          return false;
                              Severity: Minor
                              Found in lib/endpoints/class-wp-rest-comments-controller.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 delete_item has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function delete_item( $request ) {
                                      $id = (int) $request['id'];
                                      $force = isset( $request['force'] ) ? (bool) $request['force'] : false;
                              
                                      $comment = get_comment( $id );
                              Severity: Minor
                              Found in lib/endpoints/class-wp-rest-comments-controller.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 too many return statements within this method.
                              Open

                                              return new WP_Error( 'rest_comment_closed', __( 'Sorry, comments are closed on this post.' ), array( 'status' => 403 ) );
                              Severity: Major
                              Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) );
                                Severity: Major
                                Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                  return $meta_update;
                                  Severity: Major
                                  Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return $fields_update;
                                    Severity: Major
                                    Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                      return new WP_Error( 'rest_comment_trash_post', __( 'Sorry, you cannot create a comment on this post.' ), array( 'status' => 403 ) );
                                      Severity: Major
                                      Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return new WP_Error( 'rest_comment_failed_create', __( 'Creating comment failed.' ), array( 'status' => 500 ) );
                                        Severity: Major
                                        Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return current_user_can( 'edit_comment', $comment->comment_ID );
                                          Severity: Major
                                          Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                    return true;
                                            Severity: Major
                                            Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return $prepared_comment['comment_approved'];
                                              Severity: Major
                                              Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                        return $response;
                                                Severity: Major
                                                Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                          return true;
                                                  Severity: Major
                                                  Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                    return new WP_Error( $error_code, $error_message, array( 'status' => 409 ) );
                                                    Severity: Major
                                                    Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                      return new WP_Error( $error_code, $error_message, array( 'status' => 400 ) );
                                                      Severity: Major
                                                      Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                        return new WP_Error( 'rest_comment_draft_post', __( 'Sorry, you cannot create a comment on this post.' ), array( 'status' => 403 ) );
                                                        Severity: Major
                                                        Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                      return $fields_update;
                                                          Severity: Major
                                                          Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                            return $prepared_args;
                                                            Severity: Major
                                                            Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                      return rest_ensure_response( $response );
                                                              Severity: Major
                                                              Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                        return true;
                                                                Severity: Major
                                                                Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

                                                                                  return new WP_Error( 'rest_comment_author_required', __( 'Creating a comment requires a valid author name.' ), array( 'status' => 400 ) );
                                                                  Severity: Major
                                                                  Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                                    Avoid too many return statements within this method.
                                                                    Open

                                                                            return $response;
                                                                    Severity: Major
                                                                    Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                                      Avoid too many return statements within this method.
                                                                      Open

                                                                                      return $meta_update;
                                                                      Severity: Major
                                                                      Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                                        Avoid too many return statements within this method.
                                                                        Open

                                                                                    return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you cannot create this comment without a post.' ), array( 'status' => rest_authorization_required_code() ) );
                                                                        Severity: Major
                                                                        Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                                          Avoid too many return statements within this method.
                                                                          Open

                                                                                          return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
                                                                          Severity: Major
                                                                          Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                                                                            Avoid too many return statements within this method.
                                                                            Open

                                                                                            return new WP_Error( 'rest_comment_author_email_required', __( 'Creating a comment requires a valid author email.' ), array( 'status' => 400 ) );
                                                                            Severity: Major
                                                                            Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

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

                                                                                  protected function normalize_query_param( $query_param ) {
                                                                                      $prefix = 'comment_';
                                                                              
                                                                                      switch ( $query_param ) {
                                                                                          case 'id':
                                                                              Severity: Minor
                                                                              Found in lib/endpoints/class-wp-rest-comments-controller.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

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

                                                                                  protected function prepare_links( $comment ) {
                                                                                      $links = array(
                                                                                          'self' => array(
                                                                                              'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID ) ),
                                                                                          ),
                                                                              Severity: Minor
                                                                              Found in lib/endpoints/class-wp-rest-comments-controller.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

                                                                                  public function register_routes() {
                                                                              
                                                                                      register_rest_route( $this->namespace, '/' . $this->rest_base, array(
                                                                                          array(
                                                                                              'methods'   => WP_REST_Server::READABLE,
                                                                              Severity: Major
                                                                              Found in lib/endpoints/class-wp-rest-comments-controller.php and 1 other location - About 1 day to fix
                                                                              lib/endpoints/class-wp-rest-terms-controller.php on lines 57..102

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

                                                                              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

                                                                                      if ( get_option( 'show_avatars' ) ) {
                                                                                          $avatar_properties = array();
                                                                              
                                                                                          $avatar_sizes = rest_get_avatar_sizes();
                                                                                          foreach ( $avatar_sizes as $size ) {
                                                                              Severity: Major
                                                                              Found in lib/endpoints/class-wp-rest-comments-controller.php and 1 other location - About 3 hrs to fix
                                                                              lib/endpoints/class-wp-rest-users-controller.php on lines 899..919

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

                                                                              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