drhenner/ror_ecommerce

View on GitHub

Showing 203 of 346 total issues

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

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

  def show
    authorize! :create_orders, current_user

    @order = find_or_create_order
    #@order = session_admin_cart.add_items_to_checkout(order) # need here because items can also be removed
Severity: Minor
Found in app/controllers/admin/shopping/checkout/orders_controller.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

Severity
Category
Status
Source
Language