skyverge/wc-plugin-framework

View on GitHub
woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.php

Summary

Maintainability
F
3 days
Test Coverage

File Google_Pay.php has 300 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WooCommerce Payment Gateway Framework
 *
 * This source file is subject to the GNU General Public License v3.0

    Function process_payment has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        public function process_payment( $payment_data, $product_id ) {
    
            $order = null;
    
            try {

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

        public function process_payment( $payment_data, $product_id ) {
    
            $order = null;
    
            try {

      Google_Pay has 22 functions (exceeds 20 allowed). Consider refactoring.
      Open

      #[\AllowDynamicProperties]
      class Google_Pay extends External_Checkout {
      
      
          /** @var Admin the admin instance */

        Method build_display_items has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function build_display_items( \WC_Cart $cart ) {
        
                $subtotal = $cart->subtotal_ex_tax;
                $discount = $cart->get_cart_discount_total();
                $shipping = $cart->shipping_total;

          Function validate_product has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function validate_product( \WC_Product $product ) {
          
                  // no subscription products
                  if ( $this->get_plugin()->is_subscriptions_active() && \WC_Subscriptions_Product::is_subscription( $product ) ) {
                      throw new SV_WC_Payment_Gateway_Exception( 'Not available for subscription products.' );

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

              public function recalculate_totals( $chosen_shipping_method, $product_id ) {
          
                  // if this is a single product page, make sure the cart gets populated
                  $this->add_product_to_cart( $product_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

          Function build_display_items has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function build_display_items( \WC_Cart $cart ) {
          
                  $subtotal = $cart->subtotal_ex_tax;
                  $discount = $cart->get_cart_discount_total();
                  $shipping = $cart->shipping_total;

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

              public function recalculate_totals( $chosen_shipping_method, $product_id ) {
          
                  // if this is a single product page, make sure the cart gets populated
                  $this->add_product_to_cart( $product_id );
          
          

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

                public function validate_cart( \WC_Cart $cart ) {
            
                    if ( $this->get_plugin()->is_subscriptions_active() && \WC_Subscriptions_Cart::cart_contains_subscription() ) {
                        throw new SV_WC_Payment_Gateway_Exception( 'Cart contains subscriptions.' );
                    }
            Severity: Minor
            Found in woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.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 add_product_to_cart has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function add_product_to_cart( $product_id ) {
            
                    if ( ! empty( $product_id ) && $product = wc_get_product( $product_id ) ) {
            
                        if ( ! is_user_logged_in() ) {
            Severity: Minor
            Found in woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.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

                            $shipping_address = [
                                'first_name' => isset( $first_name ) ? $first_name : '',
                                'last_name'  => isset( $last_name ) ? $last_name : '',
                                'address_1'  => isset( $shipping_address_data['address1'] ) ? $shipping_address_data['address1'] : '',
                                'address_2'  => isset( $shipping_address_data['address2'] ) ? $shipping_address_data['address2'] : '',
            woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.php on lines 476..485

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

            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

                            $billing_address = [
                                'first_name' => isset( $first_name ) ? $first_name : '',
                                'last_name'  => isset( $last_name ) ? $last_name : '',
                                'address_1'  => isset( $billing_address_data['address1'] ) ? $billing_address_data['address1'] : '',
                                'address_2'  => isset( $billing_address_data['address2'] ) ? $billing_address_data['address2'] : '',
            woocommerce/payment-gateway/External_Checkout/Google_Pay/Google_Pay.php on lines 503..512

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

            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