mysociety/alaveteli

View on GitHub

Showing 409 of 413 total issues

File info_request.rb has 1377 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'digest/sha1'
require 'fileutils'

class InfoRequest < ApplicationRecord
  Guess = Struct.new(:info_request, :matched_value, :match_method).freeze
Severity: Major
Found in app/models/info_request.rb - About 3 days to fix

    Class InfoRequest has 142 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class InfoRequest < ApplicationRecord
      Guess = Struct.new(:info_request, :matched_value, :match_method).freeze
      OLD_AGE_IN_DAYS = 21.days
    
      include AdminColumn
    Severity: Major
    Found in app/models/info_request.rb - About 2 days to fix

      File acts_as_xapian.rb has 773 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      begin
        require 'xapian'
        $acts_as_xapian_bindings_available = true
      rescue LoadError
        STDERR.puts "acts_as_xapian: No Ruby bindings for Xapian installed"
      Severity: Major
      Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 day to fix

        File request_controller.rb has 712 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require 'zip'
        require 'open-uri'
        
        class RequestController < ApplicationController
          before_action :check_read_only, only: [:new, :upload_response]
        Severity: Major
        Found in app/controllers/request_controller.rb - About 1 day to fix

          File public_body.rb has 701 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require 'csv'
          require 'securerandom'
          require 'set'
          require 'confidence_intervals'
          
          
          Severity: Major
          Found in app/models/public_body.rb - About 1 day to fix

            Class User has 73 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class User < ApplicationRecord
              include AlaveteliFeatures::Helpers
              include AlaveteliPro::PhaseCounts
              include User::Authentication
            
            
            Severity: Major
            Found in app/models/user.rb - About 1 day to fix

              File routes.rb has 597 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              include AlaveteliFeatures::Constraints
              
              # Allow easy extension from themes. Note these will have the highest priority.
              $alaveteli_route_extensions.each do |f|
                load File.join('config', f)
              Severity: Major
              Found in config/routes.rb - About 1 day to fix

                File user.rb has 536 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                class User < ApplicationRecord
                  include AlaveteliFeatures::Helpers
                  include AlaveteliPro::PhaseCounts
                  include User::Authentication
                
                
                Severity: Major
                Found in app/models/user.rb - About 1 day to fix

                  Method initialize has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def initialize(user, project: nil)
                      # Define abilities for the passed in user here. For example:
                      #
                      #   user ||= User.new # guest user (not logged in)
                      #   if user.is_admin?
                  Severity: Minor
                  Found in app/models/ability.rb - About 1 day 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 xapian_index has a Cognitive Complexity of 52 (exceeds 5 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)
                          if not if_value
                  Severity: Minor
                  Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 day 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

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

                    var submitAddForm = function submitAddForm(e) {
                      e.preventDefault();
                      var $this = $(this);
                      DraftBatchSummary.startNewXHR();
                      DraftBatchSummary.currentXHR = $.ajax({
                  app/assets/javascripts/alaveteli_pro/draft_batch_summary/body.js on lines 27..47

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

                  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

                    var submitRemoveForm = function submitRemoveForm(e) {
                      e.preventDefault();
                      var $this = $(this);
                      DraftBatchSummary.startNewXHR();
                      DraftBatchSummary.currentXHR = $.ajax({
                  app/assets/javascripts/alaveteli_pro/batch_authority_search/result.js on lines 30..51

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

                  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

                  Method alert_tracks has a Cognitive Complexity of 50 (exceeds 5 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: Minor
                  Found in app/mailers/track_mailer.rb - About 7 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 get_language_name has 191 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def self.get_language_name(locale)
                      language_names = {
                        'ab'    => 'аҧсуа',
                        'aa'    => 'Afaraf',
                        'af'    => 'Afrikaans',
                  Severity: Major
                  Found in lib/languages.rb - About 7 hrs to fix

                    Class PublicBody has 52 methods (exceeds 20 allowed). Consider refactoring.
                    Open

                    class PublicBody < ApplicationRecord
                      include AdminColumn
                    
                      class ImportCSVDryRun < StandardError; end
                    
                    
                    Severity: Major
                    Found in app/models/public_body.rb - About 7 hrs to fix

                      Class OutgoingMessage has 47 methods (exceeds 20 allowed). Consider refactoring.
                      Open

                      class OutgoingMessage < ApplicationRecord
                        include AdminColumn
                        include MessageProminence
                        include Rails.application.routes.url_helpers
                        include LinkToHelper
                      Severity: Minor
                      Found in app/models/outgoing_message.rb - About 6 hrs to fix

                        Class InfoRequestEvent has 46 methods (exceeds 20 allowed). Consider refactoring.
                        Open

                        class InfoRequestEvent < ApplicationRecord
                          include AdminColumn
                          extend XapianQueries
                        
                          EVENT_TYPES = [
                        Severity: Minor
                        Found in app/models/info_request_event.rb - About 6 hrs to fix

                          Function d3TimeSeries has 158 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function d3TimeSeries(selector, data, title, metric_name) {
                          
                            // Add the title
                            var wrapper_element = document.querySelectorAll(selector)[0];
                          
                          
                          Severity: Major
                          Found in app/assets/javascripts/time_series.js - About 6 hrs to fix

                            File incoming_message.rb has 422 lines of code (exceeds 250 allowed). Consider refactoring.
                            Open

                            require 'rexml/document'
                            require 'zip'
                            require 'iconv' unless String.method_defined?(:encode)
                            
                            class IncomingMessage < ApplicationRecord
                            Severity: Minor
                            Found in app/models/incoming_message.rb - About 6 hrs to fix

                              Method import_csv_from_file has a Cognitive Complexity of 39 (exceeds 5 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: Minor
                              Found in app/models/public_body.rb - About 5 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