mysociety/alaveteli

View on GitHub

Showing 337 of 433 total issues

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

      def decode_attached_part(part, parent_mail)
        if get_content_type(part) == 'message/rfc822'
          # An email attached as text
          part.rfc822_attachment = mail_from_raw_email(part.body)
          if part.rfc822_attachment.nil?
Severity: Minor
Found in lib/mail_handler/backends/mail_backend.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 55 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def upload_response
    AlaveteliLocalization.with_locale(locale) do
      @info_request = InfoRequest.not_embargoed.find_by_url_title!(params[:url_title])

      @reason_params = {
Severity: Major
Found in app/controllers/request_controller.rb - About 2 hrs to fix

    Method render_new_compose has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def render_new_compose
        params[:info_request] = {} unless params[:info_request]
    
        # Reconstruct the params
        # first the public body (by URL name or id)
    Severity: Major
    Found in app/controllers/request_controller.rb - About 2 hrs to fix

      Class AttachmentsController has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class AttachmentsController < ApplicationController
        include FragmentCachable
        include InfoRequestHelper
        include PublicTokenable
      
      
      Severity: Minor
      Found in app/controllers/attachments_controller.rb - About 2 hrs to fix

        Method create has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def create
            set_last_request(@info_request)
        
            if params[:last_info_request_event_id].to_i != @info_request.
                last_event_id_needing_description
        Severity: Major
        Found in app/controllers/classifications_controller.rb - About 2 hrs to fix

          Method initialize_query has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def initialize_query(options)
                #raise options.to_yaml
          
                self.runtime += Benchmark.realtime {
                  offset = options[:offset] || 0
          Severity: Major
          Found in lib/acts_as_xapian/acts_as_xapian.rb - About 2 hrs to fix

            Method signchangeemail has 53 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def signchangeemail
                # "authenticated?" has done the redirect to signin page for us
                return unless authenticated? || ask_to_login(
                  web: _('To change your email address used on {{site_name}}',
                         site_name: site_name),
            Severity: Major
            Found in app/controllers/user_controller.rb - About 2 hrs to fix

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

                def create
                  if @post_redirect.present?
                    @user_signin =
                      User.authenticate_from_form(user_signin_params,
                                                  @post_redirect.reason_params[:user_name])
              Severity: Minor
              Found in app/controllers/users/sessions_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 public_bodies has 51 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def self.public_bodies
                  per_graph = 10
                  minimum_requests = AlaveteliConfiguration.minimum_requests_for_statistics
                  # Make sure minimum_requests is > 0 to avoid division-by-zero
                  minimum_requests = [minimum_requests, 1].max
              Severity: Major
              Found in app/models/statistics.rb - About 2 hrs to fix

                Method destroy_and_rebuild_index has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def self.destroy_and_rebuild_index(model_classes, verbose = false, terms = true, values = true, texts = true, safe_rebuild = true)
                    #raise "when rebuilding all, please call as first and only thing done in process / task" if not ActsAsXapian.writable_db.nil?
                    prepare_environment
                
                    update_existing = !(terms == true && values == true && texts == true)
                Severity: Minor
                Found in lib/acts_as_xapian/acts_as_xapian.rb - About 2 hrs 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)
                      unless authenticated?
                        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 load_file has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def self.load_file(file_name)
                        is_gz = file_name.include?(".gz")
                        file_name_db = is_gz ? file_name.gsub(".gz", "") : file_name
                    
                        modified = File.stat(file_name).mtime
                    Severity: Minor
                    Found in app/models/mail_server_log.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 who_can_followup_to has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def who_can_followup_to(skip_message = nil)
                        ret = []
                        done = {}
                        if skip_message
                          if (email = OutgoingMailer.email_for_followup(self, skip_message))
                    Severity: Minor
                    Found in app/models/info_request.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 each has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def each(&_block)
                        to_enum(:each) unless block_given?
                    
                        yield prepare_dashboard_metrics
                    
                    
                    Severity: Minor
                    Found in app/services/info_request_batch_zip.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 add_correspondence has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def add_correspondence
                        json = ActiveSupport::JSON.decode(params[:correspondence_json])
                        attachments = params[:attachments]
                    
                        direction = json["direction"]
                    Severity: Minor
                    Found in app/controllers/api_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 expand_and_normalize_parts has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def expand_and_normalize_parts(part, parent_mail)
                            if part.multipart?
                              Mail::PartsList.new(part.parts.each { |sub_part| expand_and_normalize_parts(sub_part, parent_mail) })
                            else
                              part_filename = get_part_file_name(part)
                    Severity: Minor
                    Found in lib/mail_handler/backends/mail_backend.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 list has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def list
                        long_cache
                    
                        @tag = params[:tag] || 'all'
                        @tag = @tag.upcase if @tag.scan(/./mu).size == 1
                    Severity: Minor
                    Found in app/controllers/public_body_controller.rb - About 1 hr to fix

                      Method new has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def new
                          if params[:comment]
                            # TODO: this check should theoretically be a validation rule in the model
                            @existing_comment = Comment.find_existing(@info_request.id, params[:comment][:body])
                          else
                      Severity: Minor
                      Found in app/controllers/comment_controller.rb - About 1 hr to fix

                        Method create_fixtures has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            def self.create_fixtures(fixtures_directory, fixture_set_names, class_names = {}, config = ActiveRecord::Base)
                              fixture_set_names = Array(fixture_set_names).map(&:to_s)
                              class_names = ClassCache.new class_names, config
                        
                              # FIXME: Apparently JK uses this.
                        Severity: Minor
                        Found in lib/no_constraint_disabling.rb - About 1 hr to fix

                          Method results has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              def results
                                # If they've already pulled out the results, just return them.
                                return cached_results unless cached_results.nil?
                          
                                docs = []
                          Severity: Minor
                          Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language