WP-API/WP-API

View on GitHub

Showing 244 of 244 total issues

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

    public function get_item_permissions_check( $request ) {
        $tax_obj = get_taxonomy( $this->taxonomy );
        if ( ! $tax_obj || ! $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 1 hr to fix
lib/endpoints/class-wp-rest-terms-controller.php on lines 110..119

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

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

Function create_item_permissions_check has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function create_item_permissions_check( $request ) {

        if ( ! is_user_logged_in() && get_option( 'comment_registration' ) ) {
            return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) );
        }
Severity: Minor
Found in lib/endpoints/class-wp-rest-comments-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 update_item has 46 lines of code (exceeds 25 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 1 hr to fix

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

        public function update_item( $request ) {
            $id = (int) $request['id'];
    
            $user = get_userdata( $id );
            if ( ! $user ) {
    Severity: Minor
    Found in lib/endpoints/class-wp-rest-users-controller.php - About 1 hr to fix

      Method register_routes has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function register_routes() {
      
              register_rest_route( $this->namespace, '/' . $this->rest_base, array(
                  array(
                      'methods'         => WP_REST_Server::READABLE,
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-posts-controller.php - About 1 hr to fix

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

                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: Major
        Found in lib/endpoints/class-wp-rest-terms-controller.php and 1 other location - About 1 hr to fix
        lib/endpoints/class-wp-rest-terms-controller.php on lines 376..386

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

        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

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

                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: Major
        Found in lib/endpoints/class-wp-rest-terms-controller.php and 1 other location - About 1 hr to fix
        lib/endpoints/class-wp-rest-terms-controller.php on lines 469..479

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

        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 upload_from_data has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function upload_from_data( $data, $headers ) {
                if ( empty( $data ) ) {
                    return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) );
                }
        
        
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 1 hr to fix

          Method get_item_schema has 44 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'                => 'type',
                      'type'                 => 'object',
          Severity: Minor
          Found in lib/endpoints/class-wp-rest-post-types-controller.php - About 1 hr to fix

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

                public function update_item( $request ) {
                    $id = (int) $request['id'];
            
                    $user = get_userdata( $id );
                    if ( ! $user ) {
            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 prepare_item_for_response has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                public function prepare_item_for_response( $post, $request ) {
                    $response = parent::prepare_item_for_response( $post, $request );
                    $data = $response->get_data();
            
                    $data['alt_text']      = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
            Severity: Minor
            Found in lib/endpoints/class-wp-rest-attachments-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_multi_meta_value has a Cognitive Complexity of 14 (exceeds 5 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

            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 sync has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                        sync: function( method, model, options ) {
                            var beforeSend, success,
                                self = this;
            
                            options    = options || {};
            Severity: Minor
            Found in wp-api.js - About 1 hr to fix

              Method register_routes has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function register_routes() {
              
                      register_rest_route( $this->namespace, '/' . $this->rest_base, array(
                          array(
                              'methods'             => WP_REST_Server::READABLE,
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-terms-controller.php - About 1 hr to fix

                Method register_routes has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function register_routes() {
                
                        register_rest_route( $this->namespace, '/' . $this->rest_base, array(
                            array(
                                'methods'   => WP_REST_Server::READABLE,
                Severity: Minor
                Found in lib/endpoints/class-wp-rest-comments-controller.php - About 1 hr to fix

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

                      public function prepare_item_for_response( $post, $request ) {
                          $response = parent::prepare_item_for_response( $post, $request );
                          $data = $response->get_data();
                  
                          $data['alt_text']      = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
                  Severity: Minor
                  Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 1 hr to fix

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