WP-API/WP-API

View on GitHub

Showing 222 of 244 total issues

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

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

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

    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

      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

          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
                        Severity
                        Category
                        Status
                        Source
                        Language