I am measuring my code for a Rails app using Rubocop. This is my code:
def ratings_treatment
if @rating.advertise_id
advertise = Advertise.find(advertise_id)
rating_average(advertise)
elsif @rating.product_id
product = Product.find(product_id)
rating_average(product)
elsif @rating.combo_id
combo = Combo.find(combo_id)
rating_average(combo)
else
establishment = Establishment.find(@rating.establishment_id)
rating_average(establishment)
end
end
It does not pass a test regarding if
. It is claimed that there are too many if
statements.
I thought of splitting the code into some checker methods, but was wondering if there is some better way to get good metrics and still write good code.