我有一个连接到 CodeClimate 的应用程序,它向我显示了一个Method upstream_transactions has a Cognitive Complexity of 6 (exceeds 5 allowed)
带有以下代码的错误:
def upstream_transactions(bank_account:, external_account:, external_transactions:)
external_transactions.each do |transaction|
next if transaction.currency != 'USD'
transfer = BankTransfer.unscoped.find_or_create_by(
添加 line 后出现此错误next if transaction.currency != 'USD'
。
def upstream_transactions(bank_account:, external_account:, external_transactions:)
external_transactions.each do |transaction|
next if transaction.currency != 'USD'
transfer = BankTransfer.unscoped.find_or_create_by(
customer_id: customer.id, transaction_identifier: transaction.transaction_id
)
next if transfer.deleted_at?
transfer.update(
date: transaction.booked_at,
# (...) some other params
)
end
Success(bank_account: bank_account, external_account: external_account)
end
如何避免这样的错误?