drhenner/ror_ecommerce

View on GitHub
app/models/cart.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Method add_variant has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def add_variant(variant_id, customer, qty = 1, cart_item_type_id = ItemType::SHOPPING_CART_ID, admin_purchase = false)
Severity: Minor
Found in app/models/cart.rb - About 35 mins to fix

    Method add_cart_items has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def add_cart_items(items, qty, customer, cart_item_type_id, variant_id)
    Severity: Minor
    Found in app/models/cart.rb - About 35 mins to fix

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

        def items_to_add_or_destroy(items_in_cart, order)
          #destroy_any_order_item_that_was_removed_from_cart
          destroy_order_items_not_in_cart!(items_in_cart, order)
         # order.order_items.delete_all #destroy(order_item.id)
          items = order.order_items.inject({}) {|h, item| h[item.variant_id].nil? ? h[item.variant_id] = [item.id]  : h[item.variant_id] << item.id; h}
      Severity: Minor
      Found in app/models/cart.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 add_variant has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def add_variant(variant_id, customer, qty = 1, cart_item_type_id = ItemType::SHOPPING_CART_ID, admin_purchase = false)
          items = shopping_cart_items.where(variant_id: variant_id).to_a
          variant = Variant.find_by(id: variant_id)
          quantity_to_purchase = variant.quantity_purchaseable_if_user_wants(qty.to_i, admin_purchase)
          if admin_purchase && (quantity_to_purchase > 0)
      Severity: Minor
      Found in app/models/cart.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 merge_with_previous_cart! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def merge_with_previous_cart!
          if user_id && previous_cart
            current_items = cart_items.map(&:variant_id)
            previous_cart.cart_items.each do |item|
              self.add_variant(item.variant_id, item.user, item.quantity) unless current_items.include?(item.variant_id)
      Severity: Minor
      Found in app/models/cart.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