WP-API/WP-API

View on GitHub

Showing 244 of 244 total issues

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

    public function get_collection_params() {
        $params = parent::get_collection_params();

        $params['context']['default'] = 'view';

Severity: Major
Found in lib/endpoints/class-wp-rest-posts-controller.php - About 5 hrs to fix

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

    <?php
    
    class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
    
        /**
    Severity: Minor
    Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 5 hrs to fix

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

          public function get_items( $request ) {
      
              // Make sure a search string is set in case the orderby is set to 'relevance'.
              if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) && empty( $request['filter']['s'] ) ) {
                  return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) );
      Severity: Major
      Found in lib/endpoints/class-wp-rest-posts-controller.php - About 4 hrs to fix

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

            public function get_items( $request ) {
        
                // Make sure a search string is set in case the orderby is set to 'relevance'.
                if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) && empty( $request['filter']['s'] ) ) {
                    return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) );
        Severity: Minor
        Found in lib/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 prepare_item_for_response has 122 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function prepare_item_for_response( $post, $request ) {
                $GLOBALS['post'] = $post;
                setup_postdata( $post );
        
                $schema = $this->get_item_schema();
        Severity: Major
        Found in lib/endpoints/class-wp-rest-posts-controller.php - About 4 hrs to fix

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

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

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

                public function filter_response_by_context( $data, $context ) {
            
                    $schema = $this->get_item_schema();
                    foreach ( $data as $key => $value ) {
                        if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) {
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-controller.php - About 4 hrs to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

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

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

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

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

                public function update_item_permissions_check( $request ) {
            
                    if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
                        return false;
                    }
            Severity: Major
            Found in lib/endpoints/class-wp-rest-terms-controller.php and 1 other location - About 4 hrs to fix
            lib/endpoints/class-wp-rest-terms-controller.php on lines 522..535

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

            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 ) {
                    if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) {
                        return false;
                    }
                    $term = get_term( (int) $request['id'], $this->taxonomy );
            Severity: Major
            Found in lib/endpoints/class-wp-rest-terms-controller.php and 1 other location - About 4 hrs to fix
            lib/endpoints/class-wp-rest-terms-controller.php on lines 443..460

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

            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

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

            class WP_REST_Posts_Controller extends WP_REST_Controller {
            
                /**
                 * Post type.
                 *
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-posts-controller.php - About 4 hrs to fix

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

                          if ( _.includes( routeEndpoint.methods, 'POST' ) || _.includes( routeEndpoint.methods, 'PUT' ) ) {
              
                              // Add any non empty args, merging them into the args object.
                              if ( ! _.isEmpty( routeEndpoint.args ) ) {
              
              
              Severity: Major
              Found in wp-api.js and 1 other location - About 3 hrs to fix
              wp-api.js on lines 194..209

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

              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 ( _.includes( routeEndpoint.methods, 'GET' ) ) {
              
                                  // Add any non empty args, merging them into the defaults object.
                                  if ( ! _.isEmpty( routeEndpoint.args ) ) {
              
              
              Severity: Major
              Found in wp-api.js and 1 other location - About 3 hrs to fix
              wp-api.js on lines 177..210

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

              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

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

                  protected function prepare_item_for_database( $request ) {
                      $prepared_post = new stdClass;
              
                      // ID.
                      if ( isset( $request['id'] ) ) {
              Severity: Major
              Found in lib/endpoints/class-wp-rest-posts-controller.php - About 3 hrs to fix

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

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

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

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

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

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 157.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

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

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

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 157.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Method rest_register_settings has 90 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function rest_register_settings() {
                    global $wp_version;
                    if ( version_compare( $wp_version, '4.7-alpha', '<' ) ) {
                        return;
                    }
                Severity: Major
                Found in plugin.php - About 3 hrs to fix

                  Function create_initial_rest_routes has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                  Open

                      function create_initial_rest_routes() {
                  
                          foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
                              $class = ! empty( $post_type->rest_controller_class ) ? $post_type->rest_controller_class : 'WP_REST_Posts_Controller';
                  
                  
                  Severity: Minor
                  Found in plugin.php - About 3 hrs to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

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

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