Updated

app/controllers / installation_controller.rb

B
90 lines of codes
14 methods
4.2 complexity/method
20 churn
58.67 complexity
0 duplications
class InstallationController < ApplicationController
  1. InstallationController assumes too much for instance variable '@account'
  2. InstallationController assumes too much for instance variable '@user'
  3. InstallationController has no descriptive comment
include AccountConcern include UserConcern before_action :authenticate_user!, except: %i[new create] before_action :set_user, except: %i[new create] before_action :set_account, only: %i[step_3 update_step_3] layout 'devise' def new end def step_1
  1. InstallationController#step_1 has the name 'step_1'
end def update_step_1
  1. InstallationController#update_step_1 has the name 'update_step_1'
if @user.update(user_params) redirect_to installation_step_2_path else render :step_1, status: :unprocessable_entity end end def step_2
  1. InstallationController#step_2 has the name 'step_2'
end def update_step_2
  1. InstallationController#update_step_2 has the name 'update_step_2'
if @user.update(user_params) bypass_sign_in(@user) redirect_to installation_step_3_path else render :step_2, status: :unprocessable_entity end end def step_3
  1. InstallationController#step_3 has the name 'step_3'
end def update_step_3
  1. InstallationController#update_step_3 has the name 'update_step_3'
if @account.update(account_params) redirect_to installation_loading_path else render :step_3, status: :unprocessable_entity end end def loading
  1. InstallationController#loading doesn't depend on instance state (maybe move it to another class?)
Installation.first.complete_installation! end def create
  1. InstallationController#create has approx 12 statements
installation = Installation.first_or_initialize user = User.find_or_initialize_by(user_params.slice('email')) installation.assign_attributes(installation_params) user.assign_attributes(user_params) user.password = SecureRandom.hex(8) installation.user = user ActiveRecord::Base.transaction do installation.save! user.save! end sign_in(user) redirect_to installation_step_1_path rescue ActiveRecord::RecordInvalid, ActionController::ParameterMissing render :new, status: :unprocessable_entity end private def set_user @user = current_user end def set_account @account = Account.first_or_initialize end def installation_params params.require(:installation).permit(:id, :key1, :key2, :token) end def user_params params.require(:user).permit(*permitted_user_params) end def account_params params.require(:account).permit(*permitted_account_params) end end