WP-API/WP-API

View on GitHub

Showing 244 of 244 total issues

Method get_registered_options has 30 lines of code (exceeds 25 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

    Function get_items_permissions_check has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function get_items_permissions_check( $request ) {
            if ( 'edit' === $request['context'] ) {
                if ( ! empty( $request['type'] ) ) {
                    $taxonomies = get_object_taxonomies( $request['type'], 'objects' );
                } else {
    Severity: Minor
    Found in lib/endpoints/class-wp-rest-taxonomies-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 check_read_permission has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function check_read_permission( $comment ) {
            if ( ! empty( $comment->comment_post_ID ) ) {
                $post = get_post( $comment->comment_post_ID );
                if ( $post ) {
                    if ( $this->check_read_post_permission( $post ) && 1 === (int) $comment->comment_approved ) {
    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

    Function get_items has a Cognitive Complexity of 10 (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-taxonomies-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 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function update_item( $request ) {
            $options = $this->get_registered_options();
            $params = $request->get_params();
    
            foreach ( $options as $name => $args ) {
    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 update_value has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function update_value( $request, $object_id ) {
            $fields = $this->get_registered_fields();
    
            foreach ( $fields as $name => $args ) {
                if ( ! array_key_exists( $name, $request ) ) {
    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 rest_sanitize_request_arg has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        function rest_sanitize_request_arg( $value, $request, $param ) {
    
            $attributes = $request->get_attributes();
            if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) {
                return $value;
    Severity: Minor
    Found in plugin.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 get_collection_params has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get_collection_params() {
            return array(
                'context'                => $this->get_context_param(),
                'page'                   => array(
                    'description'        => __( 'Current page of the collection.' ),
    Severity: Minor
    Found in lib/endpoints/class-wp-rest-controller.php - About 1 hr to fix

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

              if ( ! empty( $schema['properties']['content'] ) && isset( $request['content'] ) ) {
                  if ( is_string( $request['content'] ) ) {
                      $prepared_post->post_content = wp_filter_post_kses( $request['content'] );
                  } elseif ( isset( $request['content']['raw'] ) ) {
                      $prepared_post->post_content = wp_filter_post_kses( $request['content']['raw'] );
      Severity: Major
      Found in lib/endpoints/class-wp-rest-posts-controller.php and 1 other location - About 1 hr to fix
      lib/endpoints/class-wp-rest-posts-controller.php on lines 860..866

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

      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

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

              if ( ! empty( $schema['properties']['excerpt'] ) && isset( $request['excerpt'] ) ) {
                  if ( is_string( $request['excerpt'] ) ) {
                      $prepared_post->post_excerpt = wp_filter_post_kses( $request['excerpt'] );
                  } elseif ( isset( $request['excerpt']['raw'] ) ) {
                      $prepared_post->post_excerpt = wp_filter_post_kses( $request['excerpt']['raw'] );
      Severity: Major
      Found in lib/endpoints/class-wp-rest-posts-controller.php and 1 other location - About 1 hr to fix
      lib/endpoints/class-wp-rest-posts-controller.php on lines 851..857

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

      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 prepare_links has a Cognitive Complexity of 9 (exceeds 5 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 55 mins 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 upload_from_data has a Cognitive Complexity of 9 (exceeds 5 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 55 mins 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 9 (exceeds 5 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 55 mins 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_additional_fields_for_object has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function update_additional_fields_for_object( $object, $request ) {
              $additional_fields = $this->get_additional_fields();
      
              foreach ( $additional_fields as $field_name => $field_options ) {
                  if ( ! $field_options['update_callback'] ) {
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-controller.php - About 55 mins 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 handle_status_param has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function handle_status_param( $new_status, $comment ) {
              $old_status = wp_get_comment_status( $comment->comment_ID );
      
              if ( $new_status === $old_status ) {
                  return false;
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-comments-controller.php - About 55 mins 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_database has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          public function prepare_item_for_database( $request ) {
              $prepared_term = new stdClass;
      
              $schema = $this->get_item_schema();
              if ( isset( $request['name'] ) && ! empty( $schema['properties']['name'] ) ) {
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-terms-controller.php - About 45 mins 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 8 (exceeds 5 allowed). Consider refactoring.
      Open

          public function delete_item( $request ) {
              $id = (int) $request['id'];
              $force = isset( $request['force'] ) ? (bool) $request['force'] : false;
      
              $comment = get_comment( $id );
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-comments-controller.php - About 45 mins 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 check_role_update has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function check_role_update( $user_id, $roles ) {
              global $wp_roles;
      
              foreach ( $roles as $role ) {
      
      
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-users-controller.php - About 45 mins 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 check_read_permission has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function check_read_permission( $status ) {
              if ( true === $status->public ) {
                  return true;
              }
              if ( false === $status->internal || 'trash' === $status->name ) {
      Severity: Minor
      Found in lib/endpoints/class-wp-rest-post-statuses-controller.php - About 45 mins 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

      Avoid deeply nested control flow statements.
      Open

                          if ( $value >= $args['maximum'] || $value < $args['minimum'] ) {
                              return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: minimum number, 3: maximum number */ __( '%1$s must be between %2$d (inclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) );
                          }
      Severity: Major
      Found in plugin.php - About 45 mins to fix
        Severity
        Category
        Status
        Source
        Language