mysociety/alaveteli

View on GitHub

Showing 338 of 434 total issues

Method upload_response has a Cognitive Complexity of 19 (exceeds 5 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: 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 start has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def self.start(opt={})
    opt = DEFAULTS.dup.merge(opt)

    Thread.new do
      prev = Hash.new(0)
Severity: Minor
Found in lib/memory_profiler.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 alert_tracks has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.alert_tracks
    done_something = false
    now = Time.zone.now
    one_week_ago = now - 7.days
    User.where(["last_daily_track_email < ?", now - 1.day ]).find_each do |user|
Severity: Major
Found in app/mailers/track_mailer.rb - About 2 hrs to fix

    Class MailServerLog has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class MailServerLog < ApplicationRecord
      # `serialize` needs to be called before all other ActiveRecord code.
      # See http://stackoverflow.com/a/15610692/387558
      serialize :delivery_status, DeliveryStatusSerializer
    
    
    Severity: Minor
    Found in app/models/mail_server_log.rb - About 2 hrs to fix

      File link_to_helper.rb has 269 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      module LinkToHelper
        # Links to various models
      
        # Requests
        def request_url(info_request, options = {})
      Severity: Minor
      Found in app/helpers/link_to_helper.rb - About 2 hrs to fix

        Method new has a Cognitive Complexity of 18 (exceeds 5 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 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 update has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          def update
            @pretoken_redirect = PostRedirect.find_by(token: @pretoken) if @pretoken
        
            if @password_change_user
              @password_change_user.password = params[:password_change_user][:password]
        Severity: Minor
        Found in app/controllers/password_changes_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 set_profile_photo has a Cognitive Complexity of 18 (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)
            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 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 show has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          def show
            long_cache
            @page = get_search_page_from_params
            requests_per_page = 25
        
        
        Severity: Minor
        Found in app/controllers/public_body_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 other_country_message has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          def other_country_message
            flash.keep
        
            text = ""
            site_country_code = AlaveteliConfiguration.iso_country_code.downcase
        Severity: Minor
        Found in app/controllers/services_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 _destroy_and_rebuild_index_safely has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          def self._destroy_and_rebuild_index_safely(model_classes, verbose, terms, values, texts)
            batch_size = 1000
            model_classes.each do |model_class|
              model_class_count = model_class.count
              0.step(model_class_count, batch_size) do |i|
        Severity: Minor
        Found in lib/acts_as_xapian/acts_as_xapian.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 import_csv_from_file has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.import_csv_from_file(csv_filename, tag, tag_behaviour, dry_run, editor, available_locales = [])
            errors = []
            notes = []
            begin
              ActiveRecord::Base.transaction do
        Severity: Major
        Found in app/models/public_body.rb - About 2 hrs to fix

          Method body_request_events has 60 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def body_request_events
              feed_type = params[:feed_type]
              if @public_body.id != params[:id].to_i
                raise PermissionDenied, "#{@public_body.id} != #{params[:id]}"
              end
          Severity: Major
          Found in app/controllers/api_controller.rb - About 2 hrs to fix

            Class FoiAttachment has 22 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class FoiAttachment < ApplicationRecord
              include Rails.application.routes.url_helpers
              include LinkToHelper
              include MessageProminence
            
            
            Severity: Minor
            Found in app/models/foi_attachment.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 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 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 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 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

                    Severity
                    Category
                    Status
                    Source
                    Language