WordPress/WordPress

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

Summary

Maintainability
F
4 days
Test Coverage

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

<?php
/**
 * REST API: WP_REST_Revisions_Controller class
 *
 * @package WordPress
Severity: Major
Found in wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php - About 1 day to fix

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

        public function get_items( $request ) {
            $parent = $this->get_parent( $request['parent'] );
            if ( is_wp_error( $parent ) ) {
                return $parent;
            }
    Severity: Major
    Found in wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php - About 4 hrs to fix

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

          public function get_items( $request ) {
              $parent = $this->get_parent( $request['parent'] );
              if ( is_wp_error( $parent ) ) {
                  return $parent;
              }
      Severity: Minor
      Found in wp-includes/rest-api/endpoints/class-wp-rest-revisions-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_item_schema has 75 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-revisions-controller.php - About 3 hrs to fix

        Method prepare_item_for_response has 64 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-revisions-controller.php - About 2 hrs to fix

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

              public function register_routes() {
          
                  register_rest_route(
                      $this->namespace,
                      '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base,
          Severity: Major
          Found in wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php - About 2 hrs to fix

            Method get_collection_params has 44 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';
            
            

              Function prepare_item_for_response has a Cognitive Complexity of 14 (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;

              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 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function delete_item( $request ) {
                      $revision = $this->get_revision( $request['id'] );
                      if ( is_wp_error( $revision ) ) {
                          return $revision;
                      }

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

                    public function delete_item_permissions_check( $request ) {
                        $parent = $this->get_parent( $request['parent'] );
                        if ( is_wp_error( $parent ) ) {
                            return $parent;
                        }

                  Avoid too many return statements within this method.
                  Open

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

                        Avoid too many return statements within this method.
                        Open

                                            return new WP_Error(
                                                'rest_revision_invalid_page_number',
                                                __( 'The page number requested is larger than the number of pages available.' ),
                                                array( 'status' => 400 )
                                            );
                        Severity: Major
                        Found in wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php - About 30 mins to fix

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

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

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

                                  register_rest_route(
                                      $this->namespace,
                                      '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base,
                                      array(
                                          'args'   => array(
                          wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php on lines 72..90

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

                          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_parent( $parent_post_id ) {
                                  $error = new WP_Error(
                                      'rest_post_invalid_parent',
                                      __( 'Invalid post parent ID.' ),
                                      array( 'status' => 404 )
                          wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on lines 459..476

                          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 7 locations. Consider refactoring.
                          Open

                              public function get_items_permissions_check( $request ) {
                                  $parent = $this->get_parent( $request['parent'] );
                                  if ( is_wp_error( $parent ) ) {
                                      return $parent;
                                  }
                          wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php on lines 161..176
                          wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php on lines 137..152
                          wp-includes/rest-api/endpoints/class-wp-rest-font-families-controller.php on lines 63..78
                          wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php on lines 613..629
                          wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php on lines 714..730
                          wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php on lines 846..861

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

                          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

                                      if ( $total_revisions > 0 ) {
                                          if ( $offset >= $total_revisions ) {
                                              return new WP_Error(
                                                  'rest_revision_invalid_offset_number',
                                                  __( 'The offset number requested is larger than or equal to the number of available revisions.' ),
                          wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php on lines 209..223

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

                          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