code-mancers/invoicing

View on GitHub
lib/invoicing/taxable.rb

Summary

Maintainability
B
6 hrs
Test Coverage

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

      def generate_attr_taxable_methods(method_name) #:nodoc:

        define_method("#{method_name}_tax_rounding_error") do
          original_value = read_attribute("#{method_name}_taxed")
          return nil if original_value.nil? # Can only have a rounding error if the taxed attr was assigned
Severity: Minor
Found in lib/invoicing/taxable.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 generate_attr_taxable_methods has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def generate_attr_taxable_methods(method_name) #:nodoc:

        define_method("#{method_name}_tax_rounding_error") do
          original_value = read_attribute("#{method_name}_taxed")
          return nil if original_value.nil? # Can only have a rounding error if the taxed attr was assigned
Severity: Minor
Found in lib/invoicing/taxable.rb - About 1 hr to fix

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

        def write_attribute(attribute, value) #:nodoc:
          attribute = attribute.to_s
          attr_regex = taxable_class_info.all_args.map{|a| a.to_s }.join('|')
          @taxed_or_untaxed ||= {}
          @taxed_attributes ||= {}
    Severity: Minor
    Found in lib/invoicing/taxable.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 convert_taxable_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def convert_taxable_value(attr) #:nodoc:
          attr = attr.to_s
          attr_without_suffix = attr.sub(/(_taxed)$/, '')
          to_status = ($1 == '_taxed') ? :taxed : :untaxed
    
    
    Severity: Minor
    Found in lib/invoicing/taxable.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 convert has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

          def convert(object, attr_without_suffix, value, from_status, to_status)
    Severity: Minor
    Found in lib/invoicing/taxable.rb - About 35 mins to fix

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

            def acts_as_taxable(*args)
              Invoicing::ClassInfo.acts_as(Invoicing::Taxable, self, args)
      
              attrs = taxable_class_info.new_args.map{|a| a.to_s }
              currency_attrs = attrs + attrs.map{|attr| "#{attr}_taxed"}
      Severity: Minor
      Found in lib/invoicing/taxable.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 2 locations. Consider refactoring.
      Open

              define_method("#{method_name}_with_tax_details") do |*args|
                amount = send("#{method_name}_taxed_formatted")
                tax_details = send("#{method_name}_tax_details").to_s
                tax_details.blank? ? amount : "#{amount} #{tax_details}"
              end
      Severity: Minor
      Found in lib/invoicing/taxable.rb and 1 other location - About 25 mins to fix
      lib/invoicing/taxable.rb on lines 316..320

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

      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

              define_method("#{method_name}_with_tax_info") do |*args|
                amount = send("#{method_name}_taxed_formatted")
                tax_info = send("#{method_name}_tax_info").to_s
                tax_info.blank? ? amount : "#{amount} #{tax_info}"
              end
      Severity: Minor
      Found in lib/invoicing/taxable.rb and 1 other location - About 25 mins to fix
      lib/invoicing/taxable.rb on lines 322..326

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

      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

              define_method("#{method_name}_tax_info") do |*args|
                tax_logic = taxable_class_info.all_options[:tax_logic]
                tax_logic.tax_info({:model_object => self, :attribute => method_name, :value => send(method_name)}, *args)
      Severity: Minor
      Found in lib/invoicing/taxable.rb and 1 other location - About 15 mins to fix
      lib/invoicing/taxable.rb on lines 311..313

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

      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

              define_method("#{method_name}_tax_details") do |*args|
                tax_logic = taxable_class_info.all_options[:tax_logic]
                tax_logic.tax_details({:model_object => self, :attribute => method_name, :value => send(method_name)}, *args)
      Severity: Minor
      Found in lib/invoicing/taxable.rb and 1 other location - About 15 mins to fix
      lib/invoicing/taxable.rb on lines 306..308

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

      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