ArtOfCode-/qpixel

View on GitHub
app/controllers/users_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

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
Severity: Minor
Found in app/controllers/users_controller.rb - About 4 hrs to fix

    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]
    Severity: Minor
    Found in app/controllers/users_controller.rb - About 2 hrs to fix

      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)
      Severity: Minor
      Found in app/controllers/users_controller.rb - About 1 hr to fix

      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)
      Severity: Minor
      Found in app/controllers/users_controller.rb - About 1 hr to fix

        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
        Severity: Minor
        Found in app/controllers/users_controller.rb - About 1 hr to fix

          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 }
          Severity: Minor
          Found in app/controllers/users_controller.rb - About 1 hr to fix

            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
            Severity: Minor
            Found in app/controllers/users_controller.rb - About 1 hr to fix

              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
              Severity: Minor
              Found in app/controllers/users_controller.rb - About 1 hr to fix

              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)
              Severity: Minor
              Found in app/controllers/users_controller.rb - About 1 hr to fix

                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)
                Severity: Minor
                Found in app/controllers/users_controller.rb - About 45 mins to fix

                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 }
                Severity: Minor
                Found in app/controllers/users_controller.rb - About 45 mins to fix

                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

                There are no issues that match your filters.

                Category
                Status