woocommerce/woocommerce

View on GitHub
includes/legacy/api/v2/class-wc-api-authentication.php

Summary

Maintainability
F
6 days
Test Coverage

Method check_oauth_signature has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function check_oauth_signature( $keys, $params ) {

        $http_method = strtoupper( WC()->api->server->method );

        $base_request_uri = rawurlencode( untrailingslashit( get_woocommerce_api_url( '' ) ) . WC()->api->server->path );
Severity: Minor
Found in includes/legacy/api/v2/class-wc-api-authentication.php - About 1 hr to fix

    Method check_oauth_timestamp_and_nonce has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function check_oauth_timestamp_and_nonce( $keys, $timestamp, $nonce ) {
            global $wpdb;
    
            $valid_window = 15 * 60; // 15 minute window
    
    
    Severity: Minor
    Found in includes/legacy/api/v2/class-wc-api-authentication.php - About 1 hr to fix

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

          private function check_oauth_signature( $keys, $params ) {
      
              $http_method = strtoupper( WC()->api->server->method );
      
              $base_request_uri = rawurlencode( untrailingslashit( get_woocommerce_api_url( '' ) ) . WC()->api->server->path );
      Severity: Minor
      Found in includes/legacy/api/v2/class-wc-api-authentication.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_oauth_timestamp_and_nonce has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          private function check_oauth_timestamp_and_nonce( $keys, $timestamp, $nonce ) {
              global $wpdb;
      
              $valid_window = 15 * 60; // 15 minute window
      
      
      Severity: Minor
      Found in includes/legacy/api/v2/class-wc-api-authentication.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 perform_ssl_authentication has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          private function perform_ssl_authentication() {
      
              $params = WC()->api->server->params['GET'];
      
              // Get consumer key
      Severity: Minor
      Found in includes/legacy/api/v2/class-wc-api-authentication.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_api_key_permissions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public function check_api_key_permissions( $key_permissions ) {
              switch ( WC()->api->server->method ) {
      
                  case 'HEAD':
                  case 'GET':
      Severity: Minor
      Found in includes/legacy/api/v2/class-wc-api-authentication.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

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

          private function check_oauth_signature( $keys, $params ) {
      
              $http_method = strtoupper( WC()->api->server->method );
      
              $base_request_uri = rawurlencode( untrailingslashit( get_woocommerce_api_url( '' ) ) . WC()->api->server->path );
      Severity: Major
      Found in includes/legacy/api/v2/class-wc-api-authentication.php and 1 other location - About 2 days to fix
      includes/legacy/api/v1/class-wc-api-authentication.php on lines 228..276

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

      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

          private function check_oauth_timestamp_and_nonce( $keys, $timestamp, $nonce ) {
              global $wpdb;
      
              $valid_window = 15 * 60; // 15 minute window
      
      
      Severity: Major
      Found in includes/legacy/api/v2/class-wc-api-authentication.php and 1 other location - About 1 day to fix
      includes/legacy/api/v3/class-wc-api-authentication.php on lines 330..367

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

      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

          private function perform_ssl_authentication() {
      
              $params = WC()->api->server->params['GET'];
      
              // Get consumer key
      Severity: Major
      Found in includes/legacy/api/v2/class-wc-api-authentication.php and 1 other location - About 7 hrs to fix
      includes/legacy/api/v1/class-wc-api-authentication.php on lines 75..118

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

      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 3 locations. Consider refactoring.
      Open

          public function authenticate( $user ) {
      
              // Allow access to the index by default
              if ( '/' === WC()->api->server->path ) {
                  return new WP_User( 0 );
      Severity: Major
      Found in includes/legacy/api/v2/class-wc-api-authentication.php and 2 other locations - About 3 hrs to fix
      includes/legacy/api/v1/class-wc-api-authentication.php on lines 36..63
      includes/legacy/api/v3/class-wc-api-authentication.php on lines 36..62

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

      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 3 locations. Consider refactoring.
      Open

          private function perform_oauth_authentication() {
      
              $params = WC()->api->server->params['GET'];
      
              $param_names = array( 'oauth_consumer_key', 'oauth_timestamp', 'oauth_nonce', 'oauth_signature', 'oauth_signature_method' );
      Severity: Major
      Found in includes/legacy/api/v2/class-wc-api-authentication.php and 2 other locations - About 3 hrs to fix
      includes/legacy/api/v1/class-wc-api-authentication.php on lines 137..161
      includes/legacy/api/v3/class-wc-api-authentication.php on lines 133..156

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

      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 3 locations. Consider refactoring.
      Open

          public function check_api_key_permissions( $key_permissions ) {
              switch ( WC()->api->server->method ) {
      
                  case 'HEAD':
                  case 'GET':
      Severity: Major
      Found in includes/legacy/api/v2/class-wc-api-authentication.php and 2 other locations - About 2 hrs to fix
      includes/legacy/api/v1/class-wc-api-authentication.php on lines 371..390
      includes/legacy/api/v3/class-wc-api-authentication.php on lines 375..394

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

      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

          private function normalize_parameters( $parameters ) {
      
              $normalized_parameters = array();
      
              foreach ( $parameters as $key => $value ) {
      Severity: Major
      Found in includes/legacy/api/v2/class-wc-api-authentication.php and 1 other location - About 1 hr to fix
      includes/legacy/api/v1/class-wc-api-authentication.php on lines 298..312

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

      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 3 locations. Consider refactoring.
      Open

          private function get_keys_by_consumer_key( $consumer_key ) {
              global $wpdb;
      
              $consumer_key = wc_api_hash( sanitize_text_field( $consumer_key ) );
      
      
      Severity: Major
      Found in includes/legacy/api/v2/class-wc-api-authentication.php and 2 other locations - About 55 mins to fix
      includes/legacy/api/v1/class-wc-api-authentication.php on lines 171..187
      includes/legacy/api/v3/class-wc-api-authentication.php on lines 166..182

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

      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

      There are no issues that match your filters.

      Category
      Status