File users_controller.rb
has 346 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'net/http'
# rubocop:disable Metrics/ClassLength
class UsersController < ApplicationController
include Devise::Controllers::Rememberable
Class UsersController
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class UsersController < ApplicationController
include Devise::Controllers::Rememberable
before_action :authenticate_user!, only: [:edit_profile, :update_profile, :stack_redirect, :transfer_se_content,
:qr_login_code, :me]
Method mod_privilege_action
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def mod_privilege_action
ability = Ability.find_by internal_id: params[:ability]
return not_found if ability.internal_id == 'mod'
ua = @user.community_user.privilege(ability.internal_id)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method mod_privilege_action
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def mod_privilege_action
ability = Ability.find_by internal_id: params[:ability]
return not_found if ability.internal_id == 'mod'
ua = @user.community_user.privilege(ability.internal_id)
Method full_log
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def full_log
@posts = Post.where(user: @user).count
@comments = Comment.where(user: @user).count
@flags = Flag.where(user: @user).count
@suggested_edits = SuggestedEdit.where(user: @user).count
Method role_toggle
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def role_toggle
role_map = { mod: :is_moderator, admin: :is_admin, mod_global: :is_global_moderator, admin_global: :is_global_admin,
staff: :staff }
permission_map = { mod: :is_admin, admin: :is_global_admin, mod_global: :is_global_admin,
admin_global: :is_global_admin, staff: :staff }
Method soft_delete
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def soft_delete
if @user.is_admin || @user.is_moderator
render json: { status: 'failed', message: 'Admins and moderators cannot be deleted.' },
status: :unprocessable_entity
return
Method soft_delete
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def soft_delete
if @user.is_admin || @user.is_moderator
render json: { status: 'failed', message: 'Admins and moderators cannot be deleted.' },
status: :unprocessable_entity
return
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method update_profile
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_profile
profile_params = params.require(:user).permit(:username, :profile_markdown, :website, :twitter)
profile_params[:twitter] = profile_params[:twitter].delete('@')
if profile_params[:website].present? && URI.parse(profile_params[:website]).instance_of?(URI::Generic)
Method update_profile
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def update_profile
profile_params = params.require(:user).permit(:username, :profile_markdown, :website, :twitter)
profile_params[:twitter] = profile_params[:twitter].delete('@')
if profile_params[:website].present? && URI.parse(profile_params[:website]).instance_of?(URI::Generic)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method role_toggle
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def role_toggle
role_map = { mod: :is_moderator, admin: :is_admin, mod_global: :is_global_moderator, admin_global: :is_global_admin,
staff: :staff }
permission_map = { mod: :is_admin, admin: :is_global_admin, mod_global: :is_global_admin,
admin_global: :is_global_admin, staff: :staff }
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"