WP-API/WP-API

View on GitHub

Showing 222 of 244 total issues

Function get_value has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function get_value( $object_id, $request ) {
        $fields   = $this->get_registered_fields();
        $response = array();

        foreach ( $fields as $name => $args ) {
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

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

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

      Function buildCollectionGetter has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                  buildCollectionGetter = function( parentModel, collectionName, embedSourcePoint, embedIndex ) {
                      /**
                       * Returns a promise that resolves to the requested collection
                       *
                       * Uses the embedded data if available, otherwises fetches the
      Severity: Minor
      Found in wp-api.js - About 1 hr to fix

        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

            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

            Severity
            Category
            Status
            Source
            Language