mysociety/alaveteli

View on GitHub

Showing 420 of 433 total issues

Class RequestFilter has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

  class RequestFilter
    extend ActiveModel::Naming
    include ActiveModel::Conversion

    attr_accessor :filter, :order, :search
Severity: Minor
Found in app/models/alaveteli_pro/request_filter.rb - About 2 hrs to fix

    File wizard.js has 283 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    (function($) {
      var RefusalWizard = function(target, options) {
        this.$el = $(target);
    
        var defaults = {
    Severity: Minor
    Found in app/assets/javascripts/wizard.js - About 2 hrs to fix

      Method authenticate has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def authenticate
          if AlaveteliConfiguration.skip_admin_auth
            session[:using_admin] = 1
            nil
          elsif session[:using_admin].nil? || session[:admin_name].nil?
      Severity: Minor
      Found in app/controllers/admin_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

      Consider simplifying this complex logical expression.
      Open

          if feature_enabled? :alaveteli_pro
            # Accessing alaveteli professional
            if user && (user.is_pro_admin? || user.is_pro?)
              can :access, :alaveteli_pro
            end
      Severity: Critical
      Found in app/models/ability.rb - About 2 hrs to fix

        Class Storage has 24 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class Storage
          def initialize(klass, association, setter: :data=, getter: :data,
                         condition: nil)
            @klass = klass
            @association = association
        Severity: Minor
        Found in lib/tasks/storage/storage.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 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 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 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 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
                        Severity
                        Category
                        Status
                        Source
                        Language