mysociety/alaveteli

View on GitHub

Showing 90 of 436 total issues

Method xapian_index has 85 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def xapian_index(terms = true, values = true, texts = true)
      # if we have a conditional function for indexing, call it and destroy object if failed
      if self.class.xapian_options.include?(:if)
        if_value = xapian_value(self.class.xapian_options[:if], :boolean)
        unless if_value
Severity: Major
Found in lib/acts_as_xapian/acts_as_xapian.rb - About 3 hrs to fix

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

    RSpec.describe AlaveteliFeatures::Helpers do
      let(:instance) { Class.new { include AlaveteliFeatures::Helpers }.new }
      let(:test_backend) { Flipper.new(Flipper::Adapters::Memory.new) }
    
      around do |example|
    Severity: Major
    Found in gems/alaveteli_features/spec/helpers/disable_actor_spec.rb and 1 other location - About 3 hrs to fix
    gems/alaveteli_features/spec/helpers/enable_actor_spec.rb on lines 6..37

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

    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

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

    RSpec.describe AlaveteliFeatures::Helpers do
      let(:instance) { Class.new { include AlaveteliFeatures::Helpers }.new }
      let(:test_backend) { Flipper.new(Flipper::Adapters::Memory.new) }
    
      around do |example|
    Severity: Major
    Found in gems/alaveteli_features/spec/helpers/enable_actor_spec.rb and 1 other location - About 3 hrs to fix
    gems/alaveteli_features/spec/helpers/disable_actor_spec.rb on lines 6..39

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

    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

    Function setUpCorrespondenceCollapsing has 75 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    var setUpCorrespondenceCollapsing = function(){
      $('.js-collapsable').each(function(){
        var $collapsable = $(this);
        var $triggers = $(this).find('.js-collapsable-trigger');
        var $correspondenceHeader = $(this).find('.correspondence__header');
    Severity: Major
    Found in app/assets/javascripts/correspondence-collapse.js - About 3 hrs to fix

      Method index has 73 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def index
          # Tasks to do
          @requires_admin_requests = InfoRequest.
            find_in_state('requires_admin').
              not_embargoed
      Severity: Major
      Found in app/controllers/admin_general_controller.rb - About 2 hrs to fix

        Method add_correspondence has 72 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def add_correspondence
            json = ActiveSupport::JSON.decode(params[:correspondence_json])
            attachments = params[:attachments]
        
            direction = json["direction"]
        Severity: Major
        Found in app/controllers/api_controller.rb - About 2 hrs to fix

          Method alert_overdue_requests has 65 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.alert_overdue_requests
              info_requests = InfoRequest.where("described_state = 'waiting_response'
                          AND awaiting_description = ?
                          AND user_id is not null
                          AND use_notifications = ?
          Severity: Major
          Found in app/mailers/request_mailer.rb - About 2 hrs to fix

            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

              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

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

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

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

                                        def self.alert_expiring
                                          expiring_info_requests =
                                            InfoRequest.
                                              embargo_expiring.
                                                where(use_notifications: false).
                                    Severity: Major
                                    Found in app/mailers/alaveteli_pro/embargo_mailer.rb and 1 other location - About 1 hr to fix
                                    app/mailers/alaveteli_pro/embargo_mailer.rb on lines 38..63

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

                                    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

                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language