I have a method in my Ruby code that sets the default name for my model. Rubocop complains that Assignment Branch Condition Size is too high, 21.24/15. How can I improve this?def set_default_display_name   return unless display_name.blank?   count = user.credentials.where(type: type).count   if count == 0     self.display_name = name   elsif user.credentials.where(display_name: name).count == 0     self.display_name = name   else     self.display_name = #{name} #{count + 1}   endend
Setting the default display name for my model
ruby;ruby on rails
Notes: Conditionals are expressions in Ruby, you can (and, idiomatically, should) move the assignment outside.active_record_relation.count == 0 is ok, but active_record_relation.empty? is more declarative.I'd write:def set_default_display_name  credentials_by_type = user.credentials.where(type: type)    credentials_by_name = user.credentials.where(display_name: type)  self.display_name = case  when display_name.present?    display_name  when credentials_by_type.empty? && credentials_by_name.empty?    name  else    #{name} #{credentials_by_type.count + 1}  endend