WP-API/WP-API

View on GitHub
plugin.php

Summary

Maintainability
F
5 days
Test Coverage

Function rest_validate_request_arg has a Cognitive Complexity of 83 (exceeds 5 allowed). Consider refactoring.
Open

    function rest_validate_request_arg( $value, $request, $param ) {

        $attributes = $request->get_attributes();
        if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) {
            return true;
Severity: Minor
Found in plugin.php - About 1 day 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

File plugin.php has 400 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Plugin Name: WP REST API
 * Description: JSON-based REST API for WordPress, originally developed as part of GSoC 2013.
 * Author: WP REST API Team
Severity: Minor
Found in plugin.php - About 5 hrs to fix

    Method rest_register_settings has 90 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function rest_register_settings() {
        global $wp_version;
        if ( version_compare( $wp_version, '4.7-alpha', '<' ) ) {
            return;
        }
    Severity: Major
    Found in plugin.php - About 3 hrs to fix

      Function create_initial_rest_routes has a Cognitive Complexity of 25 (exceeds 5 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 3 hrs 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 rest_validate_request_arg has 64 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function rest_validate_request_arg( $value, $request, $param ) {
      
              $attributes = $request->get_attributes();
              if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) {
                  return true;
      Severity: Major
      Found in plugin.php - About 2 hrs 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

          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

          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 (inclusive) and %3$d (inclusive)' ), $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

                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 too many return statements within this method.
                  Open

                              return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: type name */ __( '%1$s is not of type %2$s.' ), $param, 'string' ) );
                  Severity: Major
                  Found in plugin.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return $value;
                    Severity: Major
                    Found in plugin.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                              return new WP_Error( 'rest_invalid_param', sprintf( __( '%s is not a valid IP address.' ), $value ) );
                      Severity: Major
                      Found in plugin.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                                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 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                                  return new WP_Error( 'rest_invalid_email', __( 'The email address you provided is invalid.' ) );
                          Severity: Major
                          Found in plugin.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$d (inclusive)' ), $param, $args['maximum'] ) );
                            Severity: Major
                            Found in plugin.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                      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 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                    return sanitize_text_field( $value );
                                Severity: Major
                                Found in plugin.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                          return new WP_Error( 'rest_invalid_date', __( 'The date you provided is invalid.' ) );
                                  Severity: Major
                                  Found in plugin.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                        return esc_url_raw( $value );
                                    Severity: Major
                                    Found in plugin.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                          return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$d (exclusive)' ), $param, $args['minimum'] ) );
                                      Severity: Major
                                      Found in plugin.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                            return sanitize_text_field( $value );
                                        Severity: Major
                                        Found in plugin.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                              return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$d (inclusive)' ), $param, $args['minimum'] ) );
                                          Severity: Major
                                          Found in plugin.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                                return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$d (exclusive)' ), $param, $args['maximum'] ) );
                                            Severity: Major
                                            Found in plugin.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                                      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 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                        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 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                          return true;
                                                  Severity: Major
                                                  Found in plugin.php - About 30 mins to fix

                                                    Function rest_is_boolean has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                    Open

                                                        function rest_is_boolean( $maybe_bool ) {
                                                            if ( is_bool( $maybe_bool ) ) {
                                                                return true;
                                                            }
                                                    
                                                    
                                                    Severity: Minor
                                                    Found in plugin.php - About 25 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

                                                    There are no issues that match your filters.

                                                    Category
                                                    Status