Aller au contenu

Long Method (ARCH6180)

Ce contenu n’est pas encore disponible dans votre langue.

Key ruby.quality.method-too-long · Severity info · Category quality

A method whose body exceeds the configured line threshold tends to do too many things, making it hard to read, test, and change.

def process_order(order)
validate(order)
total = 0
order.items.each { |i| total += i.price * i.qty }
apply_discount(order, total)
charge_card(order)
send_receipt(order)
update_inventory(order)
notify_warehouse(order)
log_metrics(order)
end
def process_order(order)
validate(order)
total = calculate_total(order)
charge(order, total)
fulfill(order)
end

Extract small, well-named helper methods so each one carries a single responsibility.