mysociety/alaveteli

View on GitHub
app/controllers/user_controller.rb

Summary

Maintainability
F
3 days
Test Coverage

File user_controller.rb has 453 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'set'

class UserController < ApplicationController
  include UserSpamCheck

Severity: Minor
Found in app/controllers/user_controller.rb - About 6 hrs to fix

    Class UserController has 30 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class UserController < ApplicationController
      include UserSpamCheck
    
      layout :select_layout
      # NOTE: Rails 4 syntax: change before_filter to before_action
    Severity: Minor
    Found in app/controllers/user_controller.rb - About 3 hrs to fix

      Method set_profile_photo has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_profile_photo
          # check they are logged in (the upload photo option is anyway only available when logged in)
          if authenticated_user.nil?
            flash[:error] = _("You need to be logged in to change your profile photo.")
            redirect_to frontpage_url
      Severity: Minor
      Found in app/controllers/user_controller.rb - About 2 hrs 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 signchangeemail has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def signchangeemail
          # "authenticated?" has done the redirect to signin page for us
          return unless authenticated?(
              :web => _("To change your email address used on {{site_name}}",:site_name=>site_name),
              :email => _("Then you can change your email address used on {{site_name}}",:site_name=>site_name),
      Severity: Minor
      Found in app/controllers/user_controller.rb - About 1 hr to fix

        Method set_profile_photo has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def set_profile_photo
            # check they are logged in (the upload photo option is anyway only available when logged in)
            if authenticated_user.nil?
              flash[:error] = _("You need to be logged in to change your profile photo.")
              redirect_to frontpage_url
        Severity: Minor
        Found in app/controllers/user_controller.rb - About 1 hr to fix

          Method contact has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def contact
              @recipient_user = User.find(params[:id])
          
              # Banned from messaging users?
              if authenticated_user && !authenticated_user.can_contact_other_users?
          Severity: Minor
          Found in app/controllers/user_controller.rb - About 1 hr to fix

            Method signup has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

              def signup
                # Make the user and try to save it
                @user_signup = User.new(user_params(:user_signup))
                error = false
                if @request_from_foreign_country && !verify_recaptcha
            Severity: Minor
            Found in app/controllers/user_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 wall has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def wall
                long_cache
                @display_user = set_display_user
                @is_you = current_user_is_display_user
                feed_results = Set.new
            Severity: Minor
            Found in app/controllers/user_controller.rb - About 1 hr to fix

              Method signup has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def signup
                  # Make the user and try to save it
                  @user_signup = User.new(user_params(:user_signup))
                  error = false
                  if @request_from_foreign_country && !verify_recaptcha
              Severity: Minor
              Found in app/controllers/user_controller.rb - About 1 hr to fix

                Method show has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def show
                    long_cache
                    @display_user = set_display_user
                    set_view_instance_variables
                    @same_name_users = User.find_similar_named_users(@display_user)
                Severity: Minor
                Found in app/controllers/user_controller.rb - About 1 hr to fix

                  Method signchangeemail has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def signchangeemail
                      # "authenticated?" has done the redirect to signin page for us
                      return unless authenticated?(
                          :web => _("To change your email address used on {{site_name}}",:site_name=>site_name),
                          :email => _("Then you can change your email address used on {{site_name}}",:site_name=>site_name),
                  Severity: Minor
                  Found in app/controllers/user_controller.rb - About 55 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 contact has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def contact
                      @recipient_user = User.find(params[:id])
                  
                      # Banned from messaging users?
                      if authenticated_user && !authenticated_user.can_contact_other_users?
                  Severity: Minor
                  Found in app/controllers/user_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 show has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def show
                      long_cache
                      @display_user = set_display_user
                      set_view_instance_variables
                      @same_name_users = User.find_similar_named_users(@display_user)
                  Severity: Minor
                  Found in app/controllers/user_controller.rb - About 35 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 set_show_requests has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def set_show_requests
                      # Use search query for this so can collapse and paginate easily
                      # TODO: really should just use SQL query here rather than Xapian.
                  
                      @request_states = assign_request_states(@display_user)
                  Severity: Minor
                  Found in app/controllers/user_controller.rb - About 35 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

                  Avoid too many return statements within this method.
                  Open

                        return
                  Severity: Major
                  Found in app/controllers/user_controller.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                          return
                    Severity: Major
                    Found in app/controllers/user_controller.rb - About 30 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status