WP-API/WP-API

View on GitHub

Showing 222 of 244 total issues

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

    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 (exclusive) and %3$d (exclusive)' ), $param, $args['minimum'], $args['maximum'] ) );
                        }
    Severity: Major
    Found in plugin.php - About 45 mins to fix

      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 (exclusive) and %3$d (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) );
                          }
      Severity: Major
      Found in plugin.php - About 45 mins to fix

        Function handle_status_param has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function handle_status_param( $post_status, $post_type ) {
        
                switch ( $post_status ) {
                    case 'draft':
                    case 'pending':
        Severity: Minor
        Found in lib/endpoints/class-wp-rest-posts-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 (inclusive)' ), $param, $args['minimum'], $args['maximum'] ) );
                            }
        Severity: Major
        Found in plugin.php - About 45 mins to fix

          Function prepare_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function prepare_value( $value, $request, $args ) {
                  $type = $args['schema']['type'];
          
                  // For multi-value fields, check the item type instead.
                  if ( 'array' === $type && ! empty( $args['schema']['items']['type'] ) ) {
          Severity: Minor
          Found in lib/fields/class-wp-rest-meta-fields.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

          Consider simplifying this complex logical expression.
          Open

                          if ( '' !== parentName && parentName !== routeName ) {
          
                              collectionClassName = wp.api.utils.capitalize( parentName ) + wp.api.utils.capitalize( routeName );
                              modelClassName      = mapping.models[ collectionClassName ] || collectionClassName;
                              collectionClassName = mapping.collections[ collectionClassName ] || collectionClassName;
          Severity: Major
          Found in wp-api.js - About 40 mins to fix

            Function buildModelGetter has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                        buildModelGetter = function( parentModel, modelId, modelName, embedSourcePoint, embedCheckField ) {
            Severity: Minor
            Found in wp-api.js - About 35 mins to fix

              Function upload_from_file has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function upload_from_file( $files, $headers ) {
                      if ( empty( $files ) ) {
                          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 35 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 7 (exceeds 5 allowed). Consider refactoring.
              Open

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

                  public function get_item_permissions_check( $request ) {
              
                      $post = $this->get_post( (int) $request['id'] );
              
                      if ( 'edit' === $request['context'] && $post && ! $this->check_update_permission( $post ) ) {
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-posts-controller.php - About 35 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_items_query has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  protected function prepare_items_query( $prepared_args = array(), $request = null ) {
                      $query_args = parent::prepare_items_query( $prepared_args, $request );
                      if ( empty( $query_args['post_status'] ) || ! in_array( $query_args['post_status'], array( 'inherit', 'private', 'trash' ), true ) ) {
                          $query_args['post_status'] = 'inherit';
                      }
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-attachments-controller.php - About 35 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 get_items_permissions_check has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function get_items_permissions_check( $request ) {
                      if ( 'edit' === $request['context'] ) {
                          foreach ( get_post_types( array(), 'object' ) as $post_type ) {
                              if ( ! empty( $post_type->show_in_rest ) && current_user_can( $post_type->cap->edit_posts ) ) {
                                  return true;
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-post-types-controller.php - About 35 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 get_collection_params has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function get_collection_params() {
                      $params = parent::get_collection_params();
              
                      $params['context']['default'] = 'view';
              
              
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-posts-controller.php - About 35 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 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function check_read_permission( $post ) {
                      $post_type = get_post_type_object( $post->post_type );
                      if ( ! $this->check_is_post_type_allowed( $post_type ) ) {
                          return false;
                      }
              Severity: Minor
              Found in lib/endpoints/class-wp-rest-posts-controller.php - About 35 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 too many return statements within this method.
              Open

                          return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you cannot create this comment without a post.' ), array( 'status' => rest_authorization_required_code() ) );
              Severity: Major
              Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you cannot read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) );
                Severity: Major
                Found in lib/endpoints/class-wp-rest-comments-controller.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return $response;
                  Severity: Major
                  Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return $fields_update;
                    Severity: Major
                    Found in lib/endpoints/class-wp-rest-users-controller.php - About 30 mins to fix
                      Severity
                      Category
                      Status
                      Source
                      Language