ABC Metric
The ABC score is a triplet of values that represent the size of a code segment (e.g. a method).
It consists of the following counts:
- Assignment => Variables
- Branches => Method calls
- Conditionals => Boolean and logic tests
In addition, a singular Value can be counted as following:
def order_summary(order)
total = 0 # Assignment (A)
discount = 0 # Assignment (A)
if order.vip? # Condition (C)
discount = total * 0.1 # Assignment (A)
end
order.items.each do |item| # Branch (B) - calling .each
total += item.price # Assignment (A)
end
total -= discount # Assignment (A)
puts "Total: #{total}" # Branch (B) - calling puts
logger.info("Order processed") # Branch (B) - calling logger.info
total > 0 ? total : 0 # Condition (C) - ternary
end