WP-API/WP-API

View on GitHub

Showing 222 of 244 total issues

Method update_multi_meta_value has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function update_multi_meta_value( $object_id, $name, $values ) {
        if ( ! current_user_can( 'edit_post_meta', $object_id, $name ) ) {
            return new WP_Error(
                'rest_cannot_update',
                sprintf( __( 'You do not have permission to edit the %s custom field.' ), $name ),
Severity: Minor
Found in lib/fields/class-wp-rest-meta-fields.php - About 1 hr to fix

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

        protected function prepare_links( $comment ) {
            $links = array(
                'self' => array(
                    'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID ) ),
                ),
    Severity: Minor
    Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

      Method create_initial_rest_routes has 41 lines of code (exceeds 25 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 1 hr to fix

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

            protected function prepare_links( $term ) {
                $base = $this->namespace . '/' . $this->rest_base;
                $links = array(
                    'self'       => array(
                        'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr to fix

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

              protected function prepare_item_for_database( $request ) {
                  $prepared_user = new stdClass;
          
                  $schema = $this->get_item_schema();
          
          
          Severity: Minor
          Found in lib/endpoints/class-wp-rest-users-controller.php - About 1 hr 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 create_item has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public function create_item( $request ) {
                  if ( isset( $request['parent'] ) ) {
                      if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
                          return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
                      }
          Severity: Minor
          Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr 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 prepare_item_for_response has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public function prepare_item_for_response( $post, $request ) {
          
                  $schema = $this->get_item_schema();
          
                  $data = array();
          Severity: Minor
          Found in lib/endpoints/class-wp-rest-revisions-controller.php - About 1 hr 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 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public function update_item( $request ) {
                  if ( isset( $request['parent'] ) ) {
                      if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
                          return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
                      }
          Severity: Minor
          Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr 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_database has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function prepare_item_for_database( $request ) {
                  $prepared_user = new stdClass;
          
                  $schema = $this->get_item_schema();
          
          
          Severity: Minor
          Found in lib/endpoints/class-wp-rest-users-controller.php - About 1 hr to fix

            Method get_registered_fields has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function get_registered_fields() {
                    $registered = array();
            
                    foreach ( get_registered_meta_keys( $this->get_meta_type() ) as $name => $args ) {
                        if ( empty( $args['show_in_rest'] ) ) {
            Severity: Minor
            Found in lib/fields/class-wp-rest-meta-fields.php - About 1 hr to fix

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

                  public function create_item( $request ) {
                      if ( isset( $request['parent'] ) ) {
                          if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
                              return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
                          }
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr to fix

                Function get_registered_options has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function get_registered_options() {
                        $rest_options = array();
                
                        foreach ( get_registered_settings() as $name => $args ) {
                            if ( empty( $args['show_in_rest'] ) ) {
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-settings-controller.php - About 1 hr 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 delete_item has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function delete_item( $request ) {
                        $id = (int) $request['id'];
                        $force = (bool) $request['force'];
                
                        $post = $this->get_post( $id );
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-posts-controller.php - About 1 hr 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 initialize has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        initialize: function() {
                            var model = this, deferred;
                
                            Backbone.Model.prototype.initialize.apply( model, arguments );
                
                
                Severity: Minor
                Found in wp-api.js - About 1 hr to fix

                  Method prepare_item_for_response has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function prepare_item_for_response( $item, $request ) {
                  
                          $schema = $this->get_item_schema();
                          $data = array();
                          if ( ! empty( $schema['properties']['id'] ) ) {
                  Severity: Minor
                  Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr to fix

                    Method get_items_permissions_check has 34 lines of code (exceeds 25 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 1 hr to fix

                      Method prepare_item_for_response has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function prepare_item_for_response( $comment, $request ) {
                              $data = array(
                                  'id'                 => (int) $comment->comment_ID,
                                  'post'               => (int) $comment->comment_post_ID,
                                  'parent'             => (int) $comment->comment_parent,
                      Severity: Minor
                      Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

                        Method get_endpoint_args_for_item_schema has 33 lines of code (exceeds 25 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 1 hr to fix

                          Method update_item has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function update_item( $request ) {
                                  if ( isset( $request['parent'] ) ) {
                                      if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
                                          return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
                                      }
                          Severity: Minor
                          Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr to fix

                            Method delete_item has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function delete_item( $request ) {
                                    $id = (int) $request['id'];
                                    $force = (bool) $request['force'];
                            
                                    $post = $this->get_post( $id );
                            Severity: Minor
                            Found in lib/endpoints/class-wp-rest-posts-controller.php - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language