WP-API/WP-API

View on GitHub

Showing 244 of 244 total issues

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

    public function get_items( $request ) {

        // Retrieve the list of registered collection query parameters.
        $registered = $this->get_collection_params();

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

    WP_REST_Controller has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class WP_REST_Controller {
    
        /**
         * The namespace of this controller's route.
         *
    Severity: Minor
    Found in lib/endpoints/class-wp-rest-controller.php - About 3 hrs to fix

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

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

      Cognitive Complexity

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

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

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

      Further reading

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

          public function get_items( $request ) {
      
              // Retrieve the list of registered collection query parameters.
              $registered = $this->get_collection_params();
      
      
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-terms-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 get_items has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

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

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

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

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

              protected function prepare_links( $post ) {
                  $base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
          
                  // Entity meta.
                  $links = array(
          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 21 (exceeds 5 allowed). Consider refactoring.
            Open

                public function create_item( $request ) {
                    if ( ! empty( $request['id'] ) ) {
                        return new WP_Error( 'rest_user_exists', __( 'Cannot create existing resource.' ), array( 'status' => 400 ) );
                    }
            
            
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-users-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 get_endpoint_args_for_item_schema has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
            
                    $schema                = $this->get_item_schema();
                    $schema_properties     = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
                    $endpoint_args = array();
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-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 get_item_schema has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

                public function get_item_schema() {
            
                    $schema = array(
                        '$schema'    => 'http://json-schema.org/draft-04/schema#',
                        'title'      => $this->post_type,
            Severity: Minor
            Found in lib/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 get_items has 72 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

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

              Method get_item_schema has 70 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->parent_post_type}-revision",
                          'type'       => 'object',
              Severity: Major
              Found in lib/endpoints/class-wp-rest-revisions-controller.php - About 2 hrs to fix

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

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

                Cognitive Complexity

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

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

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

                Further reading

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

                    public function update_item( $request ) {
                        $id = (int) $request['id'];
                        $post = $this->get_post( $id );
                
                        if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
                Severity: Minor
                Found in lib/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 get_item_schema has 68 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'      => 'post_tag' === $this->taxonomy ? 'tag' : $this->taxonomy,
                            'type'       => 'object',
                Severity: Major
                Found in lib/endpoints/class-wp-rest-terms-controller.php - About 2 hrs to fix

                  Function create_item has a Cognitive Complexity of 19 (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.' ), array( 'status' => 400 ) );
                          }
                  
                  
                  Severity: Minor
                  Found in lib/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 rest_validate_request_arg has 64 lines of code (exceeds 25 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: Major
                  Found in plugin.php - About 2 hrs to fix

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

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

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

                          public function create_item( $request ) {
                      
                              if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) {
                                  return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) );
                              }
                      Severity: Major
                      Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 2 hrs to fix

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

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

                        Cognitive Complexity

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

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

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

                        Further reading

                        Severity
                        Category
                        Status
                        Source
                        Language