From 88a5d4be47864892bd8ee360e32b9bb7228bdc0f Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 1 Feb 2018 15:07:39 +1100 Subject: [PATCH] Reduce cognitive complexity of LineItemSyncer#update_item_quantities --- app/services/line_item_syncer.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/services/line_item_syncer.rb b/app/services/line_item_syncer.rb index 19281fcd0b..df50c27d42 100644 --- a/app/services/line_item_syncer.rb +++ b/app/services/line_item_syncer.rb @@ -22,10 +22,7 @@ class LineItemSyncer def update_item_quantities(order) changed_standing_line_items.each do |sli| line_item = order.line_items.find_by_variant_id(sli.variant_id) - - next update_quantity(line_item, sli.quantity) if line_item.quantity == sli.quantity_was - next if line_item.quantity == sli.quantity - + next if update_quantity(line_item, sli) product_name = "#{line_item.product.name} - #{line_item.full_name}" order_update_issues.add(order, product_name) end @@ -49,7 +46,10 @@ class LineItemSyncer standing_line_items.select(&:new_record?) end - def update_quantity(line_item, quantity) - line_item.update_attributes(quantity: quantity, skip_stock_check: true) + def update_quantity(line_item, sli) + if line_item.quantity == sli.quantity_was + return line_item.update_attributes(quantity: sli.quantity, skip_stock_check: true) + end + line_item.quantity == sli.quantity end end