I have a method in my rails project that initializes a new user by copying some properties of another. The method should also retain entered parameters if saving the new user is rejected. Rubocop complains that Assignment Branch Condition Size for this method is 42.02/15. How can I improve this?def setup_user_clone    member_id = (params[:id] || params[:member_id])    @membership = Membership.find(member_id)    accounts = @membership.user.accounts.map(&:id) | [@account.id]    cloned_user = User.new @membership.user.attributes.slice('permissions')    cloned_user.game_plan_admin = @membership.user.game_plan_admin    if user_edit_params      cloned_user.email = invite_email      cloned_user.permissions = user_edit_params[:permissions]      cloned_user.accounts = Account.find(invite_app_access.map(&:to_i))      cloned_user.level = user_edit_params[:user_level]    end    profile = SettingsProfile.new @account, cloned_user    accounts |= [*cloned_user.accounts.map(&:id).to_set]    @user_edit = UserEdit.new current_user, profile, @membership.user.admin?, accounts, @membership.user.shared_credentials.map(&:id)    @method = :post  end
Initializing a new user
ruby;ruby on rails
Here's my notesFirst don't use #map and use #pluck instead (for database calls), all over your code.bad:@membership.user.accounts.map(&:id)better:@membership.user.accounts.pluck(:id)Use eager loading, to reduce queriesBad:Membership.find(member_id)Better:Membership.includes(user: :accounts).find(member_id)Because you are using users and accounts in the loops after.This whole block could be reduced to a single statementif user_edit_params  cloned_user.email = invite_email  cloned_user.permissions = user_edit_params[:permissions]  cloned_user.accounts = Account.find(invite_app_access.map(&:to_i))  cloned_user.level = user_edit_params[:user_level]endToif user_edit_params  cloned_user.assign_attributes(    email: invite_email    permissions: user_edit_params[:permissions]    accounts: Account.find(invite_app_access.map(&:to_i))    level: user_edit_params[:user_level]  )endNo idea what this does@membership.user.attributes.slice('permissions')but wouldn't this do the same ?@membership.user.permissionsLaw of DemeterAnd basically just group common stuff into single methods and call the methods inside this method, isntead of having one huge method like this