Shopify/active_merchant

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

Summary

Maintainability
F
3 days
Test Coverage

File blue_snap.rb has 537 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'nokogiri'

module ActiveMerchant
  module Billing
    class BlueSnapGateway < Gateway
Severity: Major
Found in lib/active_merchant/billing/gateways/blue_snap.rb - About 1 day to fix

    Class BlueSnapGateway has 54 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class BlueSnapGateway < Gateway
          self.test_url = 'https://sandbox.bluesnap.com/services/2'
          self.live_url = 'https://ws.bluesnap.com/services/2'
          self.supported_countries = %w(US CA GB AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE AR BO BR BZ CL CO CR DO EC GF GP GT HN HT MF MQ MX NI PA PE PR PY SV UY VE)
    
    
    Severity: Major
    Found in lib/active_merchant/billing/gateways/blue_snap.rb - About 7 hrs to fix

      Method add_shipping_contact_info has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_shipping_contact_info(doc, payment_method, options)
              if address = options[:shipping_address]
                # https://developers.bluesnap.com/v8976-XML/docs/shipping-contact-info
                doc.send('first-name', payment_method.first_name)
                doc.send('last-name', payment_method.last_name)
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/blue_snap.rb - About 1 hr 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

      Method add_3ds has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_3ds(doc, three_d_secure_options)
              eci = three_d_secure_options[:eci]
              cavv = three_d_secure_options[:cavv]
              xid = three_d_secure_options[:xid]
              ds_transaction_id = three_d_secure_options[:ds_transaction_id]
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/blue_snap.rb - About 1 hr 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

      Method add_fraud_info has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_fraud_info(doc, payment_method, options)
              doc.send('transaction-fraud-info') do
                doc.send('shopper-ip-address', options[:ip]) if options[:ip]
                if fraud_info = options[:transaction_fraud_info]
                  doc.send('fraud-session-id', fraud_info[:fraud_session_id]) if fraud_info[:fraud_session_id]
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/blue_snap.rb - About 1 hr 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

      Method add_address has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_address(doc, options)
              address = options[:billing_address]
              return unless address
      
              doc.country(address[:country]) if address[:country]
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/blue_snap.rb - 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

      Method api_request has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

            def api_request(action, request, verb, payment_method_details, options)
      Severity: Minor
      Found in lib/active_merchant/billing/gateways/blue_snap.rb - About 35 mins to fix

        Method commit has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

              def commit(action, options, verb = :post, payment_method_details = PaymentMethodDetails.new(), &block)
        Severity: Minor
        Found in lib/active_merchant/billing/gateways/blue_snap.rb - About 35 mins to fix

          Method parse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def parse(payment_method)
                  return unless payment_method
          
                  if payment_method.is_a?(String)
                    @vaulted_shopper_id, payment_method_type = payment_method.split('|')
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/blue_snap.rb - 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

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

                def store(payment_method, options = {})
                  payment_method_details = PaymentMethodDetails.new(payment_method)
          
                  commit(:store, options, :post, payment_method_details) do |doc|
                    add_personal_info(doc, payment_method, options)
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/blue_snap.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

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

                def parse(response)
                  return bad_authentication_response if response.code.to_i == 401
                  return generic_error_response(response.body) if [403, 405, 429].include?(response.code.to_i)
          
                  parsed = {}
          Severity: Minor
          Found in lib/active_merchant/billing/gateways/blue_snap.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

                AVS_CODE_TRANSLATOR = {
                  'line1: U, zip: U, name: U' => 'I',
                  'line1: U, zip: U, name: M' => 'I',
                  'line1: U, zip: U, name: N' => 'I',
                  'line1: U, zip: M, name: U' => 'P',
          Severity: Major
          Found in lib/active_merchant/billing/gateways/blue_snap.rb and 2 other locations - About 1 hr to fix
          lib/active_merchant/billing/gateways/adyen.rb on lines 202..229
          lib/active_merchant/billing/gateways/payway_dot_com.rb on lines 24..51

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

          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