woothemes/woocommerce

View on GitHub
includes/rest-api/Controllers/Version1/class-wc-rest-customers-v1-controller.php

Summary

Maintainability
F
1 wk
Test Coverage

File class-wc-rest-customers-v1-controller.php has 650 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * REST API Customers controller
 *
 * Handles requests to the /customers endpoint.

    Method get_item_schema has 214 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get_item_schema() {
            $schema = array(
                '$schema'    => 'http://json-schema.org/draft-04/schema#',
                'title'      => 'customer',
                'type'       => 'object',

      Method register_routes has 80 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function register_routes() {
              register_rest_route( $this->namespace, '/' . $this->rest_base, array(
                  array(
                      'methods'             => WP_REST_Server::READABLE,
                      'callback'            => array( $this, 'get_items' ),

        Method get_items has 64 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function get_items( $request ) {
                $prepared_args = array();
                $prepared_args['exclude'] = $request['exclude'];
                $prepared_args['include'] = $request['include'];
                $prepared_args['order']   = $request['order'];

          Method get_collection_params has 61 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function get_collection_params() {
                  $params = parent::get_collection_params();
          
                  $params['context']['default'] = 'view';
          
          

            Function update_customer_meta_fields has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function update_customer_meta_fields( $customer, $request ) {
                    $schema = $this->get_item_schema();
            
                    // Customer first name.
                    if ( isset( $request['first_name'] ) ) {

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

                public function update_item( $request ) {
                    try {
                        $id       = (int) $request['id'];
                        $customer = new WC_Customer( $id );
            
            

              Function get_items has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function get_items( $request ) {
                      $prepared_args = array();
                      $prepared_args['exclude'] = $request['exclude'];
                      $prepared_args['include'] = $request['include'];
                      $prepared_args['order']   = $request['order'];

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

                  public function prepare_item_for_response( $user_data, $request ) {
                      $customer    = new WC_Customer( $user_data->ID );
                      $_data       = $customer->get_data();
                      $last_order  = wc_get_customer_last_order( $customer->get_id() );
                      $format_date = array( 'date_created', 'date_modified' );

                Method delete_item has 29 lines of code (exceeds 25 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;
                
                

                  Method create_item has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function create_item( $request ) {
                          try {
                              if ( ! empty( $request['id'] ) ) {
                                  throw new WC_REST_Exception( 'woocommerce_rest_customer_exists', __( 'Cannot create existing resource.', 'woocommerce' ), 400 );
                              }

                    Function delete_item has a Cognitive Complexity of 9 (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;
                    
                    

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

                        public function update_item( $request ) {
                            try {
                                $id       = (int) $request['id'];
                                $customer = new WC_Customer( $id );
                    
                    

                    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 $response;

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

                                      'billing' => array(
                                          'description' => __( 'List of billing address data.', 'woocommerce' ),
                                          'type'        => 'object',
                                          'context'     => array( 'view', 'edit' ),
                                          'properties' => array(
                      includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1029..1091
                      includes/rest-api/Controllers/Version2/class-wc-rest-customers-v2-controller.php on lines 194..256
                      includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1091..1153
                      includes/rest-api/Controllers/Version3/class-wc-rest-customers-controller.php on lines 149..211

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

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

                                      'shipping' => array(
                                          'description' => __( 'List of shipping address data.', 'woocommerce' ),
                                          'type'        => 'object',
                                          'context'     => array( 'view', 'edit' ),
                                          'properties' => array(
                      includes/rest-api/Controllers/Version1/class-wc-rest-orders-v1-controller.php on lines 1092..1143
                      includes/rest-api/Controllers/Version2/class-wc-rest-customers-v2-controller.php on lines 257..308
                      includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php on lines 1154..1205
                      includes/rest-api/Controllers/Version3/class-wc-rest-customers-controller.php on lines 212..263

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

                      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

                          protected function prepare_links( $customer ) {
                              $links = array(
                                  'self' => array(
                                      'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $customer->ID ) ),
                                  ),
                      includes/rest-api/Controllers/Version1/class-wc-rest-taxes-v1-controller.php on lines 551..562
                      includes/rest-api/Controllers/Version3/class-wc-rest-data-controller.php on lines 142..153

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

                      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

                              if ( isset( $request['billing'] ) ) {
                                  foreach ( array_keys( $schema['properties']['billing']['properties'] ) as $field ) {
                                      if ( isset( $request['billing'][ $field ] ) && is_callable( array( $customer, "set_billing_{$field}" ) ) ) {
                                          $customer->{"set_billing_{$field}"}( $request['billing'][ $field ] );
                                      }
                      includes/rest-api/Controllers/Version1/class-wc-rest-customers-v1-controller.php on lines 592..598

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

                      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

                              if ( isset( $request['shipping'] ) ) {
                                  foreach ( array_keys( $schema['properties']['shipping']['properties'] ) as $field ) {
                                      if ( isset( $request['shipping'][ $field ] ) && is_callable( array( $customer, "set_shipping_{$field}" ) ) ) {
                                          $customer->{"set_shipping_{$field}"}( $request['shipping'][ $field ] );
                                      }
                      includes/rest-api/Controllers/Version1/class-wc-rest-customers-v1-controller.php on lines 583..589

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

                      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