foodcoops/foodsoft

View on GitHub
app/models/order.rb

Summary

Maintainability
D
1 day
Test Coverage

Class Order has 37 methods (exceeds 20 allowed). Consider refactoring.
Open

class Order < ApplicationRecord
  attr_accessor :ignore_warnings, :transport_distribution

  # Associations
  has_many :order_articles, dependent: :destroy
Severity: Minor
Found in app/models/order.rb - About 4 hrs to fix

    File order.rb has 304 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Order < ApplicationRecord
      attr_accessor :ignore_warnings, :transport_distribution
    
      # Associations
      has_many :order_articles, dependent: :destroy
    Severity: Minor
    Found in app/models/order.rb - About 3 hrs to fix

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

        def sum(type = :gross)
          total = 0
          if %i[net gross fc].include?(type)
            for oa in order_articles.ordered.includes(:article, :article_price)
              quantity = oa.units * oa.price.unit_quantity
      Severity: Minor
      Found in app/models/order.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 init_dates has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def init_dates
          self.starts ||= Time.now
          if FoodsoftConfig[:order_schedule]
            # try to be smart when picking a reference day
            last = begin
      Severity: Minor
      Found in app/models/order.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 sum has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def sum(type = :gross)
          total = 0
          if %i[net gross fc].include?(type)
            for oa in order_articles.ordered.includes(:article, :article_price)
              quantity = oa.units * oa.price.unit_quantity
      Severity: Minor
      Found in app/models/order.rb - About 1 hr to fix

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

          def close!(user, transaction_type = nil, financial_link = nil, create_foodcoop_transaction: false)
            raise I18n.t('orders.model.error_closed') if closed?
        
            update_price_of_group_orders!
        
        
        Severity: Minor
        Found in app/models/order.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

        Avoid deeply nested control flow statements.
        Open

                  case type
                  when :groups
                    total += goa.result * goa.order_article.price.fc_price
                  when :groups_without_markup
                    total += goa.result * goa.order_article.price.gross_price
        Severity: Major
        Found in app/models/order.rb - About 45 mins to fix

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

            def starts_before_ends
              delta = Rails.env.test? ? 1 : 0 # since Rails 4.2 tests appear to have time differences, with this validation failing
              errors.add(:ends, I18n.t('orders.model.error_starts_before_ends')) if ends && starts && ends <= (starts - delta)
              errors.add(:ends, I18n.t('orders.model.error_boxfill_before_ends')) if ends && boxfill && ends <= (boxfill - delta)
              return unless boxfill && starts && boxfill <= (starts - delta)
          Severity: Minor
          Found in app/models/order.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

          There are no issues that match your filters.

          Category
          Status