petenelson/wp-rest-api-toolbox

View on GitHub

Showing 47 of 47 total issues

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

            foreach( $endpoints as $endpoint ) {

                // Add yes/no options to remove the endpoint.
                $name = 'remove-endpoint|/' . $namespace . '/' . $endpoint;
                add_settings_field( $name, sprintf( __( '%s', 'rest-api-toolbox' ), $endpoint),
includes/settings/class-rest-api-toolbox-settings-core.php on lines 42..61

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

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

            foreach( $endpoints as $endpoint ) {

                // Add yes/no options to remove the endpoint.
                $name = 'remove-endpoint|/' . $namespace . '/' . $endpoint;
                add_settings_field( $name, sprintf( __( '%s', 'rest-api-toolbox' ), $endpoint),
Severity: Major
Found in includes/settings/class-rest-api-toolbox-settings-core.php and 1 other location - About 4 hrs to fix
includes/settings/class-rest-api-toolbox-settings-custom-post-types.php on lines 57..76

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

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

module.exports = function( grunt ) {

    'use strict';
    var banner = '/**\n * <%= pkg.homepage %>\n * Copyright (c) <%= grunt.template.today("yyyy") %>\n * This file is generated automatically. Do not edit.\n */\n';
    // Project configuration
Severity: Major
Found in Gruntfile.js - About 4 hrs to fix

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

        function enable( $positional_args, $assoc_args = array() ) {
            if ( ! empty( $positional_args ) ) {
                $core_endpoint = $positional_args[0];
    
                if ( ! in_array( $core_endpoint, REST_API_Toolbox_Common::core_endpoints() ) ) {
    Severity: Major
    Found in includes/wp-cli/class-rest-api-toolbox-rest-api-command.php and 1 other location - About 4 hrs to fix
    includes/wp-cli/class-rest-api-toolbox-rest-api-command.php on lines 20..38

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

    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

        function disable( $positional_args, $assoc_args = array() ) {
            if ( ! empty( $positional_args ) ) {
                $core_endpoint = $positional_args[0];
    
                if ( ! in_array( $core_endpoint, REST_API_Toolbox_Common::core_endpoints() ) ) {
    Severity: Major
    Found in includes/wp-cli/class-rest-api-toolbox-rest-api-command.php and 1 other location - About 4 hrs to fix
    includes/wp-cli/class-rest-api-toolbox-rest-api-command.php on lines 51..69

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

    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 endpoint_requires_authentication_filter has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

            static public function endpoint_requires_authentication_filter( $result, $rest_server, $request ) {
    
                // Get the route for the request.
                $route = $request->get_route();
    
    
    Severity: Minor
    Found in includes/class-rest-api-toolbox-common.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

    The class REST_API_Toolbox_Common has 14 public methods. Consider refactoring REST_API_Toolbox_Common to keep number of public methods under 10.
    Open

        class REST_API_Toolbox_Common {
    
            static public function plugins_loaded() {
    
                // Setup disabled filter based on the changing in WP 4.7

    TooManyPublicMethods

    Since: 0.1

    A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

    Example

    Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

    The class REST_API_Toolbox_Common has an overall complexity of 57 which is very high. The configured complexity threshold is 50.
    Open

        class REST_API_Toolbox_Common {
    
            static public function plugins_loaded() {
    
                // Setup disabled filter based on the changing in WP 4.7

    Function remove_selected_endpoints_filter has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

            static public function remove_selected_endpoints_filter( $routes ) {
    
                // Get the list of core endpoints.
                $core_settings = get_option( REST_API_Toolbox_Settings::options_key( 'core' ) );
                $core_settings = ! is_array( $core_settings ) ? array() : $core_settings;
    Severity: Minor
    Found in includes/class-rest-api-toolbox-common.php - About 2 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

    Function remove_wordpress_core_namespace_filter has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

            static public function remove_wordpress_core_namespace_filter( $response ) {
    
                $remove_all = REST_API_Toolbox_Settings::setting_is_enabled( 'core', 'remove-all-core-routes' );
                if ( $remove_all ) {
                    if ( ! empty( $response->data ) && ! empty( $response->data['namespaces'] ) ) {
    Severity: Minor
    Found in includes/class-rest-api-toolbox-common.php - About 2 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 settings_input has 49 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            static public function settings_input( $args ) {
    
                $args = wp_parse_args( $args,
                    array(
                        'name' => '',
    Severity: Minor
    Found in includes/settings/class-rest-api-toolbox-settings-base.php - About 1 hr to fix

      Avoid excessively long class names like REST_API_Toolbox_Settings_Custom_Post_Types. Keep class name length under 40.
      Open

          class REST_API_Toolbox_Settings_Custom_Post_Types extends REST_API_Toolbox_Settings_Base {
      
              static $settings_key  = 'rest-api-toolbox-settings-cpt';
      
              /**

      LongClassName

      Since: 2.9

      Detects when classes or interfaces are declared with excessively long names.

      Example

      class ATooLongClassNameThatHintsAtADesignProblem {
      
      }
      
      interface ATooLongInterfaceNameThatHintsAtADesignProblem {
      
      }

      Source https://phpmd.org/rules/naming.html#longclassname

      Function status has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          function status( $positional_args, $assoc_args = array() ) {
      
              if ( ! empty( $positional_args ) ) {
                  $core_endpoint = $positional_args[0];
      
      
      Severity: Minor
      Found in includes/wp-cli/class-rest-api-toolbox-rest-api-command.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 register_cpt_settings has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              static public function register_cpt_settings() {
                  $key = self::$settings_key;
      
                  register_setting( $key, $key, array( __CLASS__, 'sanitize_cpt_settings') );
      
      

        Method endpoint_requires_authentication_filter has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                static public function endpoint_requires_authentication_filter( $result, $rest_server, $request ) {
        
                    // Get the route for the request.
                    $route = $request->get_route();
        
        
        Severity: Minor
        Found in includes/class-rest-api-toolbox-common.php - About 1 hr to fix

          Method register_core_settings has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  static public function register_core_settings() {
                      $key = self::$settings_key;
          
                      register_setting( $key, $key, array( __CLASS__, 'sanitize_core_settings') );
          
          
          Severity: Minor
          Found in includes/settings/class-rest-api-toolbox-settings-core.php - About 1 hr to fix

            Method settings_yes_no has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    static public function settings_yes_no( $args ) {
            
                        $args = wp_parse_args( $args,
                            array(
                                'name' => '',
            Severity: Minor
            Found in includes/settings/class-rest-api-toolbox-settings-base.php - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                      if ( self::core_namespace() === $response->data['namespaces'][ $i ] ) {
                                          unset( $response->data['namespaces'][ $i ] );
                                          $response->data['namespaces'] = array_values( $response->data['namespaces'] );
                                          break;
                                      }
              Severity: Major
              Found in includes/class-rest-api-toolbox-common.php - About 45 mins to fix

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

                        static public function register_cpt_settings() {
                            $key = self::$settings_key;
                
                            register_setting( $key, $key, array( __CLASS__, 'sanitize_cpt_settings') );
                
                
                Severity: Minor
                Found in includes/settings/class-rest-api-toolbox-settings-custom-post-types.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

                Missing class import via use statement (line '163', column '22').
                Open

                                    $response = new WP_Error( 'rest_forbidden', __( "SSL is required to access the REST API" ), array( 'status' => 403 ) );

                MissingImport

                Since: 2.7.0

                Importing all external classes in a file through use statements makes them clearly visible.

                Example

                function make() {
                    return new \stdClass();
                }

                Source http://phpmd.org/rules/cleancode.html#MissingImport

                Severity
                Category
                Status
                Source
                Language