Shopify/active_merchant

View on GitHub
lib/active_merchant/billing/gateways/sage.rb

Summary

Maintainability
C
1 day
Test Coverage

File sage.rb has 350 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    class SageGateway < Gateway
      include Empty

Severity: Minor
Found in lib/active_merchant/billing/gateways/sage.rb - About 4 hrs to fix

    Class SageGateway has 32 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class SageGateway < Gateway
          include Empty
    
          self.display_name = 'http://www.sagepayments.com'
          self.homepage_url = 'Sage Payment Solutions'
    Severity: Minor
    Found in lib/active_merchant/billing/gateways/sage.rb - About 4 hrs to fix

      Method commit has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def commit(action, request)
                response = parse(
                  @gateway.ssl_post(
                    @live_url,
                    build_soap_request(action, request),
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/sage.rb - 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 3 locations. Consider refactoring.
      Open

              if shipping_address = options[:shipping_address]
                post[:C_ship_name]    = shipping_address[:name]
                post[:C_ship_address] = shipping_address[:address1]
                post[:C_ship_city]    = shipping_address[:city]
                post[:C_ship_state]   = shipping_address[:state]
      Severity: Major
      Found in lib/active_merchant/billing/gateways/sage.rb and 2 other locations - About 50 mins to fix
      lib/active_merchant/billing/gateways/instapay.rb on lines 83..89
      lib/active_merchant/billing/gateways/worldpay_us.rb on lines 108..114

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

      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

            def purchase(money, payment_method, options = {})
              post = {}
              if card_brand(payment_method) == 'check'
                source = SOURCE_ECHECK
                add_check(post, payment_method)
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/sage.rb and 1 other location - About 35 mins to fix
      lib/active_merchant/billing/gateways/sage.rb on lines 66..77

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

      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

            def credit(money, payment_method, options = {})
              post = {}
              if card_brand(payment_method) == 'check'
                source = SOURCE_ECHECK
                add_check(post, payment_method)
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/sage.rb and 1 other location - About 35 mins to fix
      lib/active_merchant/billing/gateways/sage.rb on lines 37..48

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

      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

            def add_check(post, check)
              post[:C_first_name]   = check.first_name
              post[:C_last_name]    = check.last_name
              post[:C_rte]          = check.routing_number
              post[:C_acct]         = check.account_number
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/sage.rb and 1 other location - About 30 mins to fix
      lib/active_merchant/billing/gateways/cashnet.rb on lines 104..110

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

      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

            def force_utf8(string)
              return nil unless string
      
              binary = string.encode('BINARY', invalid: :replace, undef: :replace, replace: '?') # Needed for Ruby 2.0 since #encode is a no-op if the string is already UTF-8. It's not needed for Ruby 2.1 and up since it's not a no-op there.
              binary.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/sage.rb and 1 other location - About 20 mins to fix
      lib/active_merchant/billing/gateways/pay_conex.rb on lines 89..93

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

      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