piesync/billbo

View on GitHub

Showing 12 of 12 total issues

Class Invoice has 36 methods (exceeds 20 allowed). Consider refactoring.
Open

class Invoice < Sequel::Model
  AlreadyFinalized = Class.new(StandardError)

  def self.find_or_create_by_stripe_id(stripe_id)
    transaction(isolation: :serializable,
Severity: Minor
Found in app/invoice.rb - About 4 hrs to fix

    Method finalize! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def finalize!(stripe_event_id:, stripe_object:, charge:)
        # If the document only has zero total lines, do not include it for bookkeeping.
        # This happens when a customer subscribes when still in trial or no refund lines were set.
        return if stripe_object.lines.map(&:amount).all?(&:zero?)
    
    
    Severity: Minor
    Found in lib/invoice_service.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 finalize! has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def finalize!(stripe_event_id:, stripe_object:, charge:)
        # If the document only has zero total lines, do not include it for bookkeeping.
        # This happens when a customer subscribes when still in trial or no refund lines were set.
        return if stripe_object.lines.map(&:amount).all?(&:zero?)
    
    
    Severity: Minor
    Found in lib/invoice_service.rb - About 1 hr to fix

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

                puts "migrating #{subscription.id} subscription for #{customer.id} (#{customer.email})"
                puts "country: #{customer.metadata[:country_code]} vat: #{customer.metadata[:vat_registered]}"
                puts "vat: #{vat_rate}"
      
                if execute
      Severity: Minor
      Found in migrations/taxpercent.rb and 1 other location - About 50 mins to fix
      migrations/taxpercent.rb on lines 96..106

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

      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

                puts "adding VAT to #{invoice.id} of #{customer.id} (#{customer.email})"
                puts "country: #{customer.metadata[:country_code]} vat: #{customer.metadata[:vat_registered]}"
                puts "vat: #{vat_rate}"
      
                if execute
      Severity: Minor
      Found in migrations/taxpercent.rb and 1 other location - About 50 mins to fix
      migrations/taxpercent.rb on lines 32..42

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

      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

      Avoid deeply nested control flow statements.
      Open

                  if is_closed
                    puts 'reopening invoice'
                    invoice.closed = false
                    invoice.save
                  end
      Severity: Major
      Found in migrations/taxpercent.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                    if is_closed
                      puts 'closing again'
                      invoice.closed = true
                      invoice.save
                    end
        Severity: Major
        Found in migrations/taxpercent.rb - About 45 mins to fix

          Method request has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.request(options)
                begin
                  response = execute_request(options)
                rescue SocketError => e
                  handle_restclient_error(e)
          Severity: Minor
          Found in client/billbo/stripe_like.rb - About 45 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_attributes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_attributes(data)
                case data
                when Hash
                  data.map do |(k,v)|
                    {
          Severity: Minor
          Found in client/billbo/json_util.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 perform_for_single has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def perform_for_single(invoice)
              # First load VIES data into the invoice.
              vat_service.load_vies_data(invoice: invoice) if invoice.eu? && invoice.customer_vat_number
          
              # Calculate total and vat amount in euro.
          Severity: Minor
          Found in app/job.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 valid? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def valid?(vat_number:)
              checksum = Valvat.new(vat_number).valid_checksum?
          
              # Special case for the UK as after the brexit, the VIES service does not work anymore
              # for the UK. We can however still checksum.
          Severity: Minor
          Found in lib/vat_service.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 snapshot_document has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def snapshot_document(stripe_object)
              props = {}
              # In Stripe: total = subtotal - discount + tax
              props[:total] = stripe_object.total.to_i
              props[:subtotal] = stripe_object.subtotal.to_i
          Severity: Minor
          Found in lib/invoice_service.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

          Severity
          Category
          Status
          Source
          Language