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