Updated

app/controllers/accounts / users_controller.rb

D
74 lines of codes
10 methods
9.0 complexity/method
26 churn
89.85 complexity
65 duplications
class Accounts::UsersController < InternalController
  1. Accounts::UsersController assumes too much for instance variable '@user'
  2. Accounts::UsersController assumes too much for instance variable '@users'
  3. Accounts::UsersController has no descriptive comment
include UserConcern before_action :set_user, only: %i[edit update destroy hovercard_preview] def index
  1. Similar code found in 3 nodes Locations: 0 1 2
@users = if params[:query].present?
  1. Accounts::UsersController#index calls 'params[:query]' 2 times Locations: 0 1
User.where( 'full_name ILIKE :search OR email ILIKE :search OR phone ILIKE :search', search: "%#{params[:query]}%"
  1. Accounts::UsersController#index calls 'params[:query]' 2 times Locations: 0 1
).order(updated_at: :desc) else User.all.order(created_at: :desc) end @pagy, @users = pagy(@users) end def edit; end def update params_without_blank_password = user_params.reject { |key, value| value.blank? && key.include?('password') } if @user.update(params_without_blank_password) flash[:notice] = t('flash_messages.updated', model: User.model_name.human) redirect_to edit_account_user_path(current_user.account, @user) else render :edit, status: :unprocessable_entity end end def new @user = User.new end def create
  1. Similar code found in 3 nodes Locations: 0 1 2
@user = current_user.account.users.new(user_params)
  1. Accounts::UsersController#create calls 'current_user.account' 2 times Locations: 0 1
if @user.save redirect_to account_users_path(current_user.account),
  1. Accounts::UsersController#create calls 'current_user.account' 2 times Locations: 0 1
notice: t('flash_messages.created', model: User.model_name.human) else render :new, status: :unprocessable_entity end end def destroy if @user.destroy redirect_to account_users_path(current_user.account), notice: t('flash_messages.deleted', model: User.model_name.human) end end def select_user_search @users = if params[:query].present?
  1. Accounts::UsersController#select_user_search calls 'params[:query]' 2 times Locations: 0 1
User.where( 'full_name ILIKE :search OR email ILIKE :search OR phone ILIKE :search', search: "%#{params[:query]}%"
  1. Accounts::UsersController#select_user_search calls 'params[:query]' 2 times Locations: 0 1
).order(updated_at: :desc).limit(5) else User.order(updated_at: :desc).limit(5) end end def hovercard_preview end private def set_user @user = current_user.account.users.find(params[:id]) end def user_params params.require(:user).permit(*permitted_user_params) end end