mysociety/alaveteli

View on GitHub

Showing 462 of 632 total issues

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

    Function getSortFunction has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        Sifter.prototype.getSortFunction = function(search, options) {
            var i, n, self, field, fields, fields_count, multiplier, multipliers, get_field, implicit_score, sort;
    
            self   = this;
            search = self.prepareSearch(search, options);
    Severity: Major
    Found in app/assets/javascripts/alaveteli_pro/selectize.js - About 2 hrs to fix

      Function Selectize has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          var Selectize = function($input, settings) {
              var key, i, n, dir, input, self = this;
              input = $input[0];
              input.selectize = self;
          
      Severity: Major
      Found in app/assets/javascripts/alaveteli_pro/selectize.js - 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

          Function cookie has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

          jQuery.cookie = function (key, value, options) {
          
              // key and at least value given, set cookie...
              if (arguments.length > 1 && String(value) !== "[object Object]") {
                  options = jQuery.extend({}, options);
          Severity: Minor
          Found in app/assets/javascripts/jquery.cookie.js - 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

          Function init_select has 64 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  var init_select = function($input, settings_element) {
                      var i, n, tagName, $children, order = 0;
                      var options = settings_element.options;
                      var optionsMap = {};
              
          Severity: Major
          Found in app/assets/javascripts/alaveteli_pro/selectize.js - About 2 hrs to fix

            Function plotLine has 64 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                        function plotLine(datapoints, xoffset, yoffset, axisx, axisy) {
                            var points = datapoints.points,
                                ps = datapoints.pointsize,
                                prevx = null, prevy = null;
            
            
            Severity: Major
            Found in app/assets/javascripts/jquery.flot.js - About 2 hrs to fix

              Method import_csv_from_file has 62 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 render_new_compose has 62 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def render_new_compose(batch)
                    params[:info_request] = { } if !params[:info_request]
                
                    # Reconstruct the params
                    unless batch
                Severity: Major
                Found in app/controllers/request_controller.rb - About 2 hrs to fix

                  Method calculate_event_states has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def calculate_event_states
                      curr_state = nil
                      for event in info_request_events.reverse
                        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 new has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def new
                      if params[:comment]
                        @comment = Comment.new(comment_params.merge({ :user => @user }))
                      end
                  
                  
                  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 create has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def create
                      begin
                        @token = Stripe::Token.retrieve(params[:stripeToken])
                  
                        customer = current_user.pro_account.try(:stripe_customer)
                  Severity: Minor
                  Found in app/controllers/alaveteli_pro/subscriptions_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
                      for model_class in model_classes
                        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

                  Function mixin has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      MicroPlugin.mixin = function(Interface) {
                          Interface.plugins = {};
                  
                          /**
                           * Initializes the listed plugins (with options).
                  Severity: Major
                  Found in app/assets/javascripts/alaveteli_pro/selectize.js - About 2 hrs to fix

                    Function getScoreFunction has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        Sifter.prototype.getScoreFunction = function(search, options) {
                            var self, fields, tokens, token_count, nesting;
                    
                            self        = this;
                            search      = self.prepareSearch(search, options);
                    Severity: Major
                    Found in app/assets/javascripts/alaveteli_pro/selectize.js - About 2 hrs to fix

                      Method public_bodies has 59 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          def 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

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

                        class MailServerLog < ActiveRecord::Base
                          # `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
                          Severity
                          Category
                          Status
                          Source
                          Language