mysociety/alaveteli

View on GitHub

Showing 423 of 436 total issues

Method alert_comment_on_request has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.alert_comment_on_request
    # We only check comments made in the last month - this means if the
    # cron jobs broke for more than a month events would be lost, but no
    # matter. I suspect the performance gain will be needed (with an index on updated_at)

Severity: Major
Found in app/mailers/request_mailer.rb - About 2 hrs to fix

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

      def show
        long_cache
        @page = get_search_page_from_params
        requests_per_page = 25
    
    
    Severity: Major
    Found in app/controllers/public_body_controller.rb - About 2 hrs to fix

      Method get_attachment_text_one_file has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def get_attachment_text_one_file(content_type, body, charset = 'utf-8')
          # NOTE: re. charset: TMail always tries to convert email bodies
          # to UTF8 by default, so normally it should already be that.
          text = ''
          # TODO: - tell all these command line tools to return utf-8
      Severity: Major
      Found in lib/mail_handler.rb - About 2 hrs to fix

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

        def main(in_test_mode)
          Dir.chdir($alaveteli_dir) do
            raw_message = $stdin.read
        
            begin
        Severity: Minor
        Found in script/handle-mail-replies.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 calculate_event_states has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          def calculate_event_states
            curr_state = nil
            info_request_events.reverse.each do |event|
              event.xapian_mark_needs_index # we need to reindex all events in order to update their latest_* terms
              if curr_state.nil?
        Severity: Minor
        Found in app/models/info_request.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 set_locale_fields_from_csv_row has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          def set_locale_fields_from_csv_row(is_new, locale, row, options)
            changed = ActiveSupport::OrderedHash.new
            csv_field_names = options[:field_names]
            csv_import_fields.each do |field_name, _field_notes|
              localized_field_name = self.class.localized_csv_field_name(locale, field_name)
        Severity: Minor
        Found in app/models/public_body.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 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 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

          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

            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 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

                          Severity
                          Category
                          Status
                          Source
                          Language