WP-API/WP-API

View on GitHub

Showing 222 of 244 total issues

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

<?php

class WP_REST_Posts_Controller extends WP_REST_Controller {

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

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

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

      Function rest_validate_request_arg has a Cognitive Complexity of 83 (exceeds 5 allowed). Consider refactoring.
      Open

          function rest_validate_request_arg( $value, $request, $param ) {
      
              $attributes = $request->get_attributes();
              if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) {
                  return true;
      Severity: Minor
      Found in plugin.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

      File wp-api.js has 710 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      (function( window, undefined ) {
      
          'use strict';
      
          /**
      Severity: Major
      Found in wp-api.js - About 1 day to fix

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

        <?php
        
        /**
         * Access users
         */
        Severity: Major
        Found in lib/endpoints/class-wp-rest-users-controller.php - About 1 day to fix

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

              public function get_item_schema() {
          
                  $schema = array(
                      '$schema'    => 'http://json-schema.org/draft-04/schema#',
                      'title'      => $this->post_type,
          Severity: Major
          Found in lib/endpoints/class-wp-rest-posts-controller.php - About 1 day to fix

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

            <?php
            
            /**
             * Access terms associated with a taxonomy.
             */
            Severity: Major
            Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 day to fix

              Function addMixinsAndHelpers has 208 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  wp.api.utils.addMixinsAndHelpers = function( model, modelClassName, loadingObjects ) {
              
                      var hasDate = false,
              
                          /**
              Severity: Major
              Found in wp-api.js - About 1 day to fix

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

                    protected function prepare_item_for_database( $request ) {
                        $prepared_post = new stdClass;
                
                        // ID.
                        if ( isset( $request['id'] ) ) {
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-posts-controller.php - About 7 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 148 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

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

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

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

                    File plugin.php has 400 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    <?php
                    /**
                     * Plugin Name: WP REST API
                     * Description: JSON-based REST API for WordPress, originally developed as part of GSoC 2013.
                     * Author: WP REST API Team
                    Severity: Minor
                    Found in plugin.php - About 5 hrs to fix

                      Function constructFromSchema has 139 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                              constructFromSchema: function() {
                                  var routeModel = this, modelRoutes, collectionRoutes, schemaRoot, loadingObjects,
                      
                                  /**
                                   * Set up the model and collection name mapping options. As the schema is built, the
                      Severity: Major
                      Found in wp-api.js - About 5 hrs to fix

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

                            public function prepare_item_for_response( $post, $request ) {
                                $GLOBALS['post'] = $post;
                                setup_postdata( $post );
                        
                                $schema = $this->get_item_schema();
                        Severity: Minor
                        Found in lib/endpoints/class-wp-rest-posts-controller.php - About 5 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_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
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language