foodcoops/foodsoft

View on GitHub
app/models/article.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Method convert_units has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  def convert_units(new_article = shared_article)
    return unless unit != new_article.unit
    return false if new_article.unit.include?(',')

    # legacy, used by foodcoops in Germany
Severity: Minor
Found in app/models/article.rb - About 2 hrs 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_units has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def convert_units(new_article = shared_article)
    return unless unit != new_article.unit
    return false if new_article.unit.include?(',')

    # legacy, used by foodcoops in Germany
Severity: Minor
Found in app/models/article.rb - About 1 hr to fix

    Method unequal_attributes has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def unequal_attributes(new_article, options = {})
        # try to convert different units when desired
        if options[:convert_units] == false
          new_price = nil
          new_unit_quantity = nil
    Severity: Minor
    Found in app/models/article.rb - About 1 hr to fix

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

        def uniqueness_of_name
          matches = Article.where(name: name, supplier_id: supplier_id, deleted_at: deleted_at, type: type)
          matches = matches.where.not(id: id) unless new_record?
          # supplier should always be there - except, perhaps, on initialization (on seeding)
          if supplier && (supplier.shared_sync_method.blank? || supplier.shared_sync_method == 'import')
      Severity: Minor
      Found in app/models/article.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

      There are no issues that match your filters.

      Category
      Status