woothemes/woocommerce

View on GitHub
includes/legacy/api/v1/class-wc-api-customers.php

Summary

Maintainability
F
3 days
Test Coverage

Method get_customer has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function get_customer( $id, $fields = null ) {
        global $wpdb;

        $id = $this->validate_request( $id, 'customer', 'read' );

Severity: Minor
Found in includes/legacy/api/v1/class-wc-api-customers.php - About 1 hr to fix

    Method add_customer_data has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function add_customer_data( $order_data, $order ) {
    
            if ( 0 == $order->get_user_id() ) {
    
                // add customer data from order
    Severity: Minor
    Found in includes/legacy/api/v1/class-wc-api-customers.php - About 1 hr to fix

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

          private function query_customers( $args = array() ) {
      
              // default users per page
              $users_per_page = get_option( 'posts_per_page' );
      
      
      Severity: Minor
      Found in includes/legacy/api/v1/class-wc-api-customers.php - About 1 hr to fix

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

            protected function validate_request( $id, $type, $context ) {
        
                $id = absint( $id );
        
                // validate ID
        Severity: Minor
        Found in includes/legacy/api/v1/class-wc-api-customers.php - About 1 hr to fix

          Function validate_request has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function validate_request( $id, $type, $context ) {
          
                  $id = absint( $id );
          
                  // validate ID
          Severity: Minor
          Found in includes/legacy/api/v1/class-wc-api-customers.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

          Avoid too many return statements within this method.
          Open

                              return new WP_Error( 'woocommerce_api_user_cannot_delete_customer', __( 'You do not have permission to delete this customer', 'woocommerce' ), array( 'status' => 401 ) );
          Severity: Major
          Found in includes/legacy/api/v1/class-wc-api-customers.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return $id;
            Severity: Major
            Found in includes/legacy/api/v1/class-wc-api-customers.php - About 30 mins to fix

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

                  private function query_customers( $args = array() ) {
              
                      // default users per page
                      $users_per_page = get_option( 'posts_per_page' );
              
              
              Severity: Minor
              Found in includes/legacy/api/v1/class-wc-api-customers.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

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

                  public function add_customer_data( $order_data, $order ) {
              
                      if ( 0 == $order->get_user_id() ) {
              
                          // add customer data from order
              Severity: Major
              Found in includes/legacy/api/v1/class-wc-api-customers.php and 2 other locations - About 1 day to fix
              includes/legacy/api/v2/class-wc-api-customers.php on lines 637..679
              includes/legacy/api/v3/class-wc-api-customers.php on lines 627..669

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

              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

                  public function get_customer_orders( $id, $fields = null ) {
                      global $wpdb;
              
                      $id = $this->validate_request( $id, 'customer', 'read' );
              
              
              Severity: Major
              Found in includes/legacy/api/v1/class-wc-api-customers.php and 1 other location - About 5 hrs to fix
              includes/legacy/api/v2/class-wc-api-customers.php on lines 474..502

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

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

                  public function register_routes( $routes ) {
              
                      # GET /customers
                      $routes[ $this->base ] = array(
                          array( array( $this, 'get_customers' ),     WC_API_SERVER::READABLE ),
              Severity: Major
              Found in includes/legacy/api/v1/class-wc-api-customers.php and 2 other locations - About 3 hrs to fix
              includes/legacy/api/v1/class-wc-api-coupons.php on lines 34..57
              includes/legacy/api/v1/class-wc-api-products.php on lines 35..58

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

              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 get_customers( $fields = null, $filter = array(), $page = 1 ) {
              
                      $filter['page'] = $page;
              
                      $query = $this->query_customers( $filter );
              Severity: Major
              Found in includes/legacy/api/v1/class-wc-api-customers.php and 2 other locations - About 2 hrs to fix
              includes/legacy/api/v2/class-wc-api-customers.php on lines 109..129
              includes/legacy/api/v3/class-wc-api-customers.php on lines 109..129

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

              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