mysociety/alaveteli

View on GitHub
app/controllers/request_controller.rb

Summary

Maintainability
F
1 wk
Test Coverage

File request_controller.rb has 936 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'zip/zip'
require 'open-uri'

class RequestController < ApplicationController
  before_filter :check_read_only, :only => [ :new, :describe_state, :upload_response ]
Severity: Major
Found in app/controllers/request_controller.rb - About 2 days to fix

    Class RequestController has 44 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class RequestController < ApplicationController
      before_filter :check_read_only, :only => [ :new, :describe_state, :upload_response ]
      before_filter :check_batch_requests_and_user_allowed, :only => [ :select_authorities, :new_batch ]
      before_filter :set_render_recaptcha, :only => [ :new ]
      before_filter :redirect_numeric_id_to_url_title, :only => [:show]
    Severity: Minor
    Found in app/controllers/request_controller.rb - About 6 hrs to fix

      Method new has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

        def new
          # All new requests are of normal_sort
          if !params[:outgoing_message].nil?
            params[:outgoing_message][:what_doing] = 'normal_sort'
          end
      Severity: Minor
      Found in app/controllers/request_controller.rb - About 4 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 new has 89 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def new
          # All new requests are of normal_sort
          if !params[:outgoing_message].nil?
            params[:outgoing_message][:what_doing] = 'normal_sort'
          end
      Severity: Major
      Found in app/controllers/request_controller.rb - About 3 hrs to fix

        Method describe_state has 87 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def describe_state
            info_request = InfoRequest.not_embargoed.find(params[:id].to_i)
            set_last_request(info_request)
        
            # If this is an external request, go to the request page - we don't allow
        Severity: Major
        Found in app/controllers/request_controller.rb - About 3 hrs to fix

          Method render_new_compose has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

            def render_new_compose(batch)
              params[:info_request] = { } if !params[:info_request]
          
              # Reconstruct the params
              unless batch
          Severity: Minor
          Found in app/controllers/request_controller.rb - About 3 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 render_new_compose has 62 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def render_new_compose(batch)
              params[:info_request] = { } if !params[:info_request]
          
              # Reconstruct the params
              unless batch
          Severity: Major
          Found in app/controllers/request_controller.rb - About 2 hrs to fix

            Method describe_state has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

              def describe_state
                info_request = InfoRequest.not_embargoed.find(params[:id].to_i)
                set_last_request(info_request)
            
                # If this is an external request, go to the request page - we don't allow
            Severity: Minor
            Found in app/controllers/request_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 upload_response has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def upload_response
                @locale = AlaveteliLocalization.locale
                AlaveteliLocalization.with_locale(@locale) do
                  @info_request = InfoRequest.not_embargoed.find_by_url_title!(params[:url_title])
            
            
            Severity: Minor
            Found in app/controllers/request_controller.rb - About 2 hrs to fix

              Method cache_attachments has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                def cache_attachments
                  if !params[:skip_cache].nil?
                    yield
                  else
                    key = params.merge(:only_path => true)
              Severity: Minor
              Found in app/controllers/request_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 upload_response has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                def upload_response
                  @locale = AlaveteliLocalization.locale
                  AlaveteliLocalization.with_locale(@locale) do
                    @info_request = InfoRequest.not_embargoed.find_by_url_title!(params[:url_title])
              
              
              Severity: Minor
              Found in app/controllers/request_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 new_batch has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def new_batch
                  if params[:public_body_ids].blank?
                    redirect_to select_authorities_path and return
                  end
              
              
              Severity: Minor
              Found in app/controllers/request_controller.rb - About 1 hr to fix

                Method select_authorities has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                  def select_authorities
                    if !params[:public_body_query].nil?
                      @search_bodies = typeahead_search(params[:public_body_query],
                                                        :model => PublicBody,
                                                        :per_page => 1000 )
                Severity: Minor
                Found in app/controllers/request_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 show has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                  def show
                    medium_cache
                    @locale = AlaveteliLocalization.locale
                    AlaveteliLocalization.with_locale(@locale) do
                      # Look up by new style text names
                Severity: Minor
                Found in app/controllers/request_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 assign_variables_for_show_template has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def assign_variables_for_show_template(info_request)
                    @info_request = info_request
                    @info_request_events = info_request.info_request_events
                    @status = info_request.calculate_status
                    @old_unclassified =
                Severity: Minor
                Found in app/controllers/request_controller.rb - About 1 hr to fix

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

                    def show
                      medium_cache
                      @locale = AlaveteliLocalization.locale
                      AlaveteliLocalization.with_locale(@locale) do
                        # Look up by new style text names
                  Severity: Minor
                  Found in app/controllers/request_controller.rb - About 1 hr to fix

                    Method get_attachment_internal has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def get_attachment_internal(html_conversion)
                        @incoming_message = IncomingMessage.find(params[:incoming_message_id])
                        @requested_request = InfoRequest.find(params[:id])
                        @incoming_message.parse_raw_email!
                        @info_request = @incoming_message.info_request
                    Severity: Minor
                    Found in app/controllers/request_controller.rb - About 1 hr to fix

                      Method download_entire_request has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def download_entire_request
                          @locale = AlaveteliLocalization.locale
                          AlaveteliLocalization.with_locale(@locale) do
                            @info_request = InfoRequest.find_by_url_title!(params[:url_title])
                            # Check for access and hide emargoed requests immediately, so that we
                      Severity: Minor
                      Found in app/controllers/request_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 make_request_summary_file has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def make_request_summary_file(info_request)
                          done = false
                          convert_command = AlaveteliConfiguration::html_to_pdf_command
                          @render_to_file = true
                          assign_variables_for_show_template(info_request)
                      Severity: Minor
                      Found in app/controllers/request_controller.rb - About 1 hr to fix

                        Method list has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def list
                            # respond with a 404 without a database lookup if request was not for html
                            if request.format && !request.format.html?
                              respond_to { |format| format.any { head :not_found } }
                              return
                        Severity: Minor
                        Found in app/controllers/request_controller.rb - About 1 hr to fix

                          Method cache_attachments has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            def cache_attachments
                              if !params[:skip_cache].nil?
                                yield
                              else
                                key = params.merge(:only_path => true)
                          Severity: Minor
                          Found in app/controllers/request_controller.rb - About 1 hr to fix

                            Method list has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def list
                                # respond with a 404 without a database lookup if request was not for html
                                if request.format && !request.format.html?
                                  respond_to { |format| format.any { head :not_found } }
                                  return
                            Severity: Minor
                            Found in app/controllers/request_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 get_attachment_internal has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def get_attachment_internal(html_conversion)
                                @incoming_message = IncomingMessage.find(params[:incoming_message_id])
                                @requested_request = InfoRequest.find(params[:id])
                                @incoming_message.parse_raw_email!
                                @info_request = @incoming_message.info_request
                            Severity: Minor
                            Found in app/controllers/request_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 new_batch has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def new_batch
                                if params[:public_body_ids].blank?
                                  redirect_to select_authorities_path and return
                                end
                            
                            
                            Severity: Minor
                            Found in app/controllers/request_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 make_request_summary_file has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def make_request_summary_file(info_request)
                                done = false
                                convert_command = AlaveteliConfiguration::html_to_pdf_command
                                @render_to_file = true
                                assign_variables_for_show_template(info_request)
                            Severity: Minor
                            Found in app/controllers/request_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/request_controller.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

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

                                Avoid too many return statements within this method.
                                Open

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

                                  Avoid too many return statements within this method.
                                  Open

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

                                    Avoid too many return statements within this method.
                                    Open

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

                                      Avoid too many return statements within this method.
                                      Open

                                            handle_spam_subject(@info_request.user) && return
                                      Severity: Major
                                      Found in app/controllers/request_controller.rb - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                              handle_blocked_ip(@info_request) && return
                                        Severity: Major
                                        Found in app/controllers/request_controller.rb - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

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

                                            Avoid too many return statements within this method.
                                            Open

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

                                              Avoid too many return statements within this method.
                                              Open

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

                                                Avoid too many return statements within this method.
                                                Open

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

                                                  Avoid too many return statements within this method.
                                                  Open

                                                        redirect_to frontpage_path and return
                                                  Severity: Major
                                                  Found in app/controllers/request_controller.rb - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

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

                                                      Avoid too many return statements within this method.
                                                      Open

                                                              return self.theme_describe_state(info_request)
                                                      Severity: Major
                                                      Found in app/controllers/request_controller.rb - About 30 mins to fix

                                                        Method info_request_params has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                          def info_request_params(batch = false)
                                                            if batch
                                                              unless params[:info_request].nil? || params[:info_request].empty?
                                                                params.require(:info_request).permit(:title, :tag_string)
                                                              end
                                                        Severity: Minor
                                                        Found in app/controllers/request_controller.rb - About 25 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

                                                        Similar blocks of code found in 2 locations. Consider refactoring.
                                                        Open

                                                          def handle_spam_subject(user)
                                                            if send_exception_notifications?
                                                              e = Exception.new("Spam request from user #{ user.id }")
                                                              ExceptionNotifier.notify_exception(e, :env => request.env)
                                                            end
                                                        Severity: Minor
                                                        Found in app/controllers/request_controller.rb and 1 other location - About 30 mins to fix
                                                        app/controllers/comment_controller.rb on lines 140..150

                                                        Duplicated Code

                                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                        Tuning

                                                        This issue has a mass of 33.

                                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                        Refactorings

                                                        Further Reading

                                                        There are no issues that match your filters.

                                                        Category
                                                        Status