WordPress/WordPress

View on GitHub
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Summary

Maintainability
F
3 wks
Test Coverage

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

<?php
/**
 * REST API: WP_REST_Posts_Controller class
 *
 * @package WordPress
Severity: Major
Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 5 days to fix

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

        public function get_item_schema() {
            if ( $this->schema ) {
                return $this->add_additional_fields_schema( $this->schema );
            }
    
    
    Severity: Major
    Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 1 day to fix

      Function prepare_item_for_response has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
      Open

          public function prepare_item_for_response( $item, $request ) {
              // Restores the more descriptive, specific name for use within this method.
              $post = $item;
      
              $GLOBALS['post'] = $post;
      Severity: Minor
      Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 1 day 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_item_for_database has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function prepare_item_for_database( $request ) {
              $prepared_post  = new stdClass();
              $current_status = '';
      
              // Post ID.
      Severity: Minor
      Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 1 day 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_response has 192 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function prepare_item_for_response( $item, $request ) {
              // Restores the more descriptive, specific name for use within this method.
              $post = $item;
      
              $GLOBALS['post'] = $post;
      Severity: Major
      Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 7 hrs to fix

        Method get_collection_params has 145 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 wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 5 hrs to fix

          Method prepare_item_for_database has 144 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function prepare_item_for_database( $request ) {
                  $prepared_post  = new stdClass();
                  $current_status = '';
          
                  // Post ID.
          Severity: Major
          Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 5 hrs to fix

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

                public function get_items( $request ) {
            
                    // Ensure a search string is set in case the orderby is set to 'relevance'.
                    if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) {
                        return new WP_Error(
            Severity: Major
            Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 5 hrs to fix

              WP_REST_Posts_Controller has 40 functions (exceeds 20 allowed). Consider refactoring.
              Open

              class WP_REST_Posts_Controller extends WP_REST_Controller {
                  /**
                   * Post type.
                   *
                   * @since 4.7.0
              Severity: Minor
              Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 5 hrs to fix

                Function get_items has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function get_items( $request ) {
                
                        // Ensure a search string is set in case the orderby is set to 'relevance'.
                        if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) {
                            return new WP_Error(
                Severity: Minor
                Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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

                Method get_schema_links has 102 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function get_schema_links() {
                
                        $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" );
                
                        $links = array();
                Severity: Major
                Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 4 hrs to fix

                  Function get_item_schema has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function get_item_schema() {
                          if ( $this->schema ) {
                              return $this->add_additional_fields_schema( $this->schema );
                          }
                  
                  
                  Severity: Minor
                  Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 prepare_tax_query has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private function prepare_tax_query( array $args, WP_REST_Request $request ) {
                          $relation = $request['tax_relation'];
                  
                          if ( $relation ) {
                              $args['tax_query'] = array( 'relation' => $relation );
                  Severity: Minor
                  Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 prepare_links has 84 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function prepare_links( $post ) {
                          // Entity meta.
                          $links = array(
                              'self'       => array(
                                  'href' => rest_url( rest_get_route_for_post( $post->ID ) ),
                  Severity: Major
                  Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 3 hrs to fix

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

                        public function update_item( $request ) {
                            $valid_check = $this->get_post( $request['id'] );
                            if ( is_wp_error( $valid_check ) ) {
                                return $valid_check;
                            }
                    Severity: Minor
                    Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 update_item has 76 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function update_item( $request ) {
                            $valid_check = $this->get_post( $request['id'] );
                            if ( is_wp_error( $valid_check ) ) {
                                return $valid_check;
                            }
                    Severity: Major
                    Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 3 hrs to fix

                      Method create_item has 75 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function create_item( $request ) {
                              if ( ! empty( $request['id'] ) ) {
                                  return new WP_Error(
                                      'rest_post_exists',
                                      __( 'Cannot create existing post.' ),
                      Severity: Major
                      Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 3 hrs to fix

                        Method prepare_taxonomy_limit_schema has 74 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            private function prepare_taxonomy_limit_schema( array $query_params ) {
                                $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
                        
                                if ( ! $taxonomies ) {
                                    return $query_params;
                        Severity: Major
                        Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 2 hrs to fix

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

                              public function register_routes() {
                          
                                  register_rest_route(
                                      $this->namespace,
                                      '/' . $this->rest_base,
                          Severity: Major
                          Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 2 hrs to fix

                            Function create_item has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function create_item( $request ) {
                                    if ( ! empty( $request['id'] ) ) {
                                        return new WP_Error(
                                            'rest_post_exists',
                                            __( 'Cannot create existing post.' ),
                            Severity: Minor
                            Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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

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

                                protected function prepare_links( $post ) {
                                    // Entity meta.
                                    $links = array(
                                        'self'       => array(
                                            'href' => rest_url( rest_get_route_for_post( $post->ID ) ),
                            Severity: Minor
                            Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 delete_item has 57 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function delete_item( $request ) {
                                    $post = $this->get_post( $request['id'] );
                                    if ( is_wp_error( $post ) ) {
                                        return $post;
                                    }
                            Severity: Major
                            Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 2 hrs to fix

                              Method prepare_tax_query has 56 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  private function prepare_tax_query( array $args, WP_REST_Request $request ) {
                                      $relation = $request['tax_relation'];
                              
                                      if ( $relation ) {
                                          $args['tax_query'] = array( 'relation' => $relation );
                              Severity: Major
                              Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 2 hrs to fix

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

                                    protected function get_available_actions( $post, $request ) {
                                
                                        if ( 'edit' !== $request['context'] ) {
                                            return array();
                                        }
                                Severity: Minor
                                Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 check_assign_terms_permission has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    protected function check_assign_terms_permission( $request ) {
                                        $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
                                        foreach ( $taxonomies as $taxonomy ) {
                                            $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
                                
                                
                                Severity: Minor
                                Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 create_item_permissions_check has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public function create_item_permissions_check( $request ) {
                                        if ( ! empty( $request['id'] ) ) {
                                            return new WP_Error(
                                                'rest_post_exists',
                                                __( 'Cannot create existing post.' ),
                                Severity: Minor
                                Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 1 hr to fix

                                  Function sanitize_post_statuses has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public function sanitize_post_statuses( $statuses, $request, $parameter ) {
                                          $statuses = wp_parse_slug_list( $statuses );
                                  
                                          // The default status is different in WP_REST_Attachments_Controller.
                                          $attributes     = $request->get_attributes();
                                  Severity: Minor
                                  Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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_permissions_check has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      public function update_item_permissions_check( $request ) {
                                          $post = $this->get_post( $request['id'] );
                                          if ( is_wp_error( $post ) ) {
                                              return $post;
                                          }
                                  Severity: Minor
                                  Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 1 hr to fix

                                    Method get_available_actions has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        protected function get_available_actions( $post, $request ) {
                                    
                                            if ( 'edit' !== $request['context'] ) {
                                                return array();
                                            }
                                    Severity: Minor
                                    Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 1 hr to fix

                                      Function delete_item has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                          public function delete_item( $request ) {
                                              $post = $this->get_post( $request['id'] );
                                              if ( is_wp_error( $post ) ) {
                                                  return $post;
                                              }
                                      Severity: Minor
                                      Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 handle_status_param has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                          protected function handle_status_param( $post_status, $post_type ) {
                                      
                                              switch ( $post_status ) {
                                                  case 'draft':
                                                  case 'pending':
                                      Severity: Minor
                                      Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 1 hr to fix

                                        Method get_item_permissions_check has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                            public function get_item_permissions_check( $request ) {
                                                $post = $this->get_post( $request['id'] );
                                                if ( is_wp_error( $post ) ) {
                                                    return $post;
                                                }
                                        Severity: Minor
                                        Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 1 hr to fix

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

                                              public function check_read_permission( $post ) {
                                                  $post_type = get_post_type_object( $post->post_type );
                                                  if ( ! $this->check_is_post_type_allowed( $post_type ) ) {
                                                      return false;
                                                  }
                                          Severity: Minor
                                          Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 handle_status_param has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                              protected function handle_status_param( $post_status, $post_type ) {
                                          
                                                  switch ( $post_status ) {
                                                      case 'draft':
                                                      case 'pending':
                                          Severity: Minor
                                          Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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

                                          Function get_item_permissions_check has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                              public function get_item_permissions_check( $request ) {
                                                  $post = $this->get_post( $request['id'] );
                                                  if ( is_wp_error( $post ) ) {
                                                      return $post;
                                                  }
                                          Severity: Minor
                                          Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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

                                          Consider simplifying this complex logical expression.
                                          Open

                                                  if (
                                                      ( ! empty( $schema['properties']['date_gmt'] ) && $request->has_param( 'date_gmt' ) && null === $request['date_gmt'] ) ||
                                                      ( ! empty( $schema['properties']['date'] ) && $request->has_param( 'date' ) && null === $request['date'] )
                                                  ) {
                                                      $prepared_post->post_date_gmt = null;
                                          Severity: Major
                                          Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 40 mins to fix

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

                                                protected function prepare_items_query( $prepared_args = array(), $request = null ) {
                                                    $query_args = array();
                                            
                                                    foreach ( $prepared_args as $key => $value ) {
                                                        /**
                                            Severity: Minor
                                            Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.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 new WP_Error(
                                                                    'rest_post_invalid_id',
                                                                    __( 'Invalid post parent ID.' ),
                                                                    array( 'status' => 400 )
                                                                );
                                            Severity: Major
                                            Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

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

                                                Avoid too many return statements within this method.
                                                Open

                                                            return new WP_Error(
                                                                'rest_cannot_delete',
                                                                __( 'The post cannot be deleted.' ),
                                                                array( 'status' => 500 )
                                                            );
                                                Severity: Major
                                                Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

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

                                                    Avoid too many return statements within this method.
                                                    Open

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

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return new WP_Error(
                                                                      'rest_cannot_assign_term',
                                                                      __( 'Sorry, you are not allowed to assign the provided terms.' ),
                                                                      array( 'status' => rest_authorization_required_code() )
                                                                  );
                                                      Severity: Major
                                                      Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                    return new WP_Error(
                                                                        'rest_cannot_assign_term',
                                                                        __( 'Sorry, you are not allowed to assign the provided terms.' ),
                                                                        array( 'status' => rest_authorization_required_code() )
                                                                    );
                                                        Severity: Major
                                                        Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

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

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                      return apply_filters( "rest_pre_insert_{$this->post_type}", $prepared_post, $request );
                                                              Severity: Major
                                                              Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                                return new WP_Error(
                                                                                    'rest_invalid_field',
                                                                                    __( 'A password protected post can not be set to sticky.' ),
                                                                                    array( 'status' => 400 )
                                                                                );
                                                                Severity: Major
                                                                Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

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

                                                                    Avoid too many return statements within this method.
                                                                    Open

                                                                                        return new WP_Error(
                                                                                            'rest_invalid_field',
                                                                                            __( 'A sticky post can not be password protected.' ),
                                                                                            array( 'status' => 400 )
                                                                                        );
                                                                    Severity: Major
                                                                    Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 30 mins to fix

                                                                      Avoid too many return statements within this method.
                                                                      Open

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

                                                                        Avoid too many return statements within this method.
                                                                        Open

                                                                                    return $fields_update;
                                                                        Severity: Major
                                                                        Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 30 mins to fix

                                                                            Avoid too many return statements within this method.
                                                                            Open

                                                                                    return false;
                                                                            Severity: Major
                                                                            Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php - About 30 mins to fix

                                                                              Avoid too many return statements within this method.
                                                                              Open

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

                                                                                Avoid too many return statements within this method.
                                                                                Open

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

                                                                                  Avoid too many return statements within this method.
                                                                                  Open

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

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

                                                                                        public function get_collection_params() {
                                                                                            $query_params = parent::get_collection_params();
                                                                                    
                                                                                            $query_params['context']['default'] = 'view';
                                                                                    
                                                                                    
                                                                                    Severity: Minor
                                                                                    Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 update_item_permissions_check has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                    Open

                                                                                        public function update_item_permissions_check( $request ) {
                                                                                            $post = $this->get_post( $request['id'] );
                                                                                            if ( is_wp_error( $post ) ) {
                                                                                                return $post;
                                                                                            }
                                                                                    Severity: Minor
                                                                                    Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 handle_terms has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                    Open

                                                                                        protected function handle_terms( $post_id, $request ) {
                                                                                            $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
                                                                                    
                                                                                            foreach ( $taxonomies as $taxonomy ) {
                                                                                                $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
                                                                                    Severity: Minor
                                                                                    Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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 create_item_permissions_check has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                    Open

                                                                                        public function create_item_permissions_check( $request ) {
                                                                                            if ( ! empty( $request['id'] ) ) {
                                                                                                return new WP_Error(
                                                                                                    'rest_post_exists',
                                                                                                    __( 'Cannot create existing post.' ),
                                                                                    Severity: Minor
                                                                                    Found in wp-includes/rest-api/endpoints/class-wp-rest-posts-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

                                                                                                        $schema['properties']['title'] = array(
                                                                                                            'description' => __( 'The title for the post.' ),
                                                                                                            'type'        => 'object',
                                                                                                            'context'     => array( 'view', 'edit', 'embed' ),
                                                                                                            'arg_options' => array(
                                                                                    wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php on lines 948..969

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

                                                                                    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

                                                                                    Identical blocks of code found in 2 locations. Consider refactoring.
                                                                                    Open

                                                                                            register_rest_route(
                                                                                                $this->namespace,
                                                                                                '/' . $this->rest_base,
                                                                                                array(
                                                                                                    array(
                                                                                    wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php on lines 84..103

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

                                                                                    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 ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
                                                                                                $links = $this->prepare_links( $post );
                                                                                                $response->add_links( $links );
                                                                                    
                                                                                                if ( ! empty( $links['self']['href'] ) ) {
                                                                                    wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php on lines 613..626

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

                                                                                    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

                                                                                        protected function get_post( $id ) {
                                                                                            $error = new WP_Error(
                                                                                                'rest_post_invalid_id',
                                                                                                __( 'Invalid post ID.' ),
                                                                                                array( 'status' => 404 )
                                                                                    wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on lines 150..170

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

                                                                                    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

                                                                                        public function delete_item_permissions_check( $request ) {
                                                                                            $post = $this->get_post( $request['id'] );
                                                                                            if ( is_wp_error( $post ) ) {
                                                                                                return $post;
                                                                                            }
                                                                                    wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php on lines 212..227

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

                                                                                    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 ( $post_type->hierarchical || 'attachment' === $this->post_type ) {
                                                                                                $query_params['parent']         = array(
                                                                                                    'description' => __( 'Limit result set to items with particular parent IDs.' ),
                                                                                                    'type'        => 'array',
                                                                                                    'items'       => array(
                                                                                    wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on lines 2817..2834

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

                                                                                    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 ( post_type_supports( $this->post_type, 'author' ) ) {
                                                                                                $query_params['author']         = array(
                                                                                                    'description' => __( 'Limit result set to posts assigned to specific authors.' ),
                                                                                                    'type'        => 'array',
                                                                                                    'items'       => array(
                                                                                    wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on lines 2909..2926

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

                                                                                    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