Noosfero/noosfero

View on GitHub
plugins/orders/models/orders_plugin/order.rb

Summary

Maintainability
D
1 day
Test Coverage

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

class OrdersPlugin::Order < ApplicationRecord
  # if abstract_class is true then it will trigger https://github.com/rails/rails/issues/20871
  # self.abstract_class = true

  Statuses = ::OrdersPlugin::Item::Statuses
Severity: Minor
Found in plugins/orders/models/orders_plugin/order.rb - About 4 hrs to fix

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

    class OrdersPlugin::Order < ApplicationRecord
      # if abstract_class is true then it will trigger https://github.com/rails/rails/issues/20871
      # self.abstract_class = true
    
      Statuses = ::OrdersPlugin::Item::Statuses
    Severity: Minor
    Found in plugins/orders/models/orders_plugin/order.rb - About 3 hrs to fix

      Method fill_items has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def fill_items(from_status, to_status, save = false)
          # check for status advance
          return if (Statuses.index(to_status) <= Statuses.index(from_status) rescue true)
      
          from_data = StatusDataMap[from_status]
      Severity: Minor
      Found in plugins/orders/models/orders_plugin/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 situation has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def situation
          current_index = UserStatuses.index self.current_status || 0
          statuses = []
          UserStatuses.each_with_index do |status, i|
            statuses << status if Statuses.include? status
      Severity: Minor
      Found in plugins/orders/models/orders_plugin/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

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

        def self_supplier?
          return @self_supplier if @self_supplier
      
          self.items.each do |item|
            return @self_supplier = false unless (item.product.supplier.self? rescue true)
      Severity: Minor
      Found in plugins/orders/models/orders_plugin/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

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

        def self.supplier_products_by_suppliers(orders)
          products_by_supplier = {}
          items = self.parent::Item.where(order_id: orders.map(&:id)).includes(sources_supplier_products: [:supplier, :from_product])
          items.each do |item|
            if item.sources_supplier_products.present?
      Severity: Minor
      Found in plugins/orders/models/orders_plugin/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

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

          def send_notifications
            # shopping_cart has its notifications
            return if source == "shopping_cart_plugin"
            # ignore when status is being rewinded
            return if (Statuses.index(self.status) <= Statuses.index(self.status_was) rescue false)
      Severity: Minor
      Found in plugins/orders/models/orders_plugin/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

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

          def change_status
            return if self.status_was == self.status
      
            self.fill_items self.status_was, self.status, true
            self.items.update_all status: self.status
      Severity: Minor
      Found in plugins/orders/models/orders_plugin/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

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

        def self.search_scope(scope, params)
          scope = scope.with_status params[:status] if params[:status].present?
          scope = scope.for_consumer_id params[:consumer_id] if params[:consumer_id].present?
          scope = scope.for_profile_id params[:supplier_id] if params[:supplier_id].present?
          scope = scope.with_code params[:code] if params[:code].present?
      Severity: Minor
      Found in plugins/orders/models/orders_plugin/order.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 next_status has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def next_status(actor_name)
          # allow supplier to confirm and receive orders if admin is true
          actor_statuses = if actor_name == :supplier then Statuses else StatusesByActor[actor_name] end
          # if no status was found go to the first (-1 to 0)
          current_index = Statuses.index(self.status) || -1
      Severity: Minor
      Found in plugins/orders/models/orders_plugin/order.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

      There are no issues that match your filters.

      Category
      Status