mysociety/alaveteli

View on GitHub
app/models/public_body.rb

Summary

Maintainability
F
5 days
Test Coverage

File public_body.rb has 692 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 PublicBody has 51 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class PublicBody < ActiveRecord::Base
      include AdminColumn
    
      class ImportCSVDryRun < StandardError ; end
    
    
    Severity: Major
    Found in app/models/public_body.rb - About 7 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

      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 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 import_values_from_csv_row has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def import_values_from_csv_row(row, line, name, options)
            is_new = new_record?
            edit_info = if is_new
              { :action => "creating new authority",
                :comment => 'Created from spreadsheet' }
        Severity: Minor
        Found in app/models/public_body.rb - About 1 hr 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 with_query has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.with_query(query, tag)
            like_query = "%#{query}%"
            has_first_letter = tag.size == 1
        
            underscore_locale = AlaveteliLocalization.locale
        Severity: Minor
        Found in app/models/public_body.rb - About 1 hr to fix

          Method get_request_percentages has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.get_request_percentages(column, n, highest, minimum_requests)
              total_column = "info_requests_visible_classified_count"
              ordering = "y_value"
              ordering += " DESC" if highest
              y_value_column = "(cast(#{column} as float) / #{total_column})"
          Severity: Minor
          Found in app/models/public_body.rb - About 1 hr to fix

            Method internal_admin_body has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.internal_admin_body
                matching_pbs = PublicBody.where(:url_name => 'internal_admin_authority')
                case
                when matching_pbs.empty? then
                  # "internal admin" exists but has the wrong default locale - fix & return
            Severity: Minor
            Found in app/models/public_body.rb - About 1 hr to fix

              Method compare has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  def compare(previous = nil, &block)
                    if previous.nil?
                      changes = []
                    else
                      v = self
              Severity: Minor
              Found in app/models/public_body.rb - About 1 hr 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_values_from_csv_row has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def import_values_from_csv_row(row, line, name, options)
                  is_new = new_record?
                  edit_info = if is_new
                    { :action => "creating new authority",
                      :comment => 'Created from spreadsheet' }
              Severity: Minor
              Found in app/models/public_body.rb - About 1 hr to fix

                Method set_locale_fields_from_csv_row has 26 lines of code (exceeds 25 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 1 hr to fix

                  Method import_csv has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def self.import_csv(csv, tag, tag_behaviour, dry_run, editor, available_locales = [])
                  Severity: Minor
                  Found in app/models/public_body.rb - About 45 mins to fix

                    Method import_csv_from_file has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      def self.import_csv_from_file(csv_filename, tag, tag_behaviour, dry_run, editor, available_locales = [])
                    Severity: Minor
                    Found in app/models/public_body.rb - About 45 mins to fix

                      Method with_query has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def self.with_query(query, tag)
                          like_query = "%#{query}%"
                          has_first_letter = tag.size == 1
                      
                          underscore_locale = AlaveteliLocalization.locale
                      Severity: Minor
                      Found in app/models/public_body.rb - About 45 mins 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 calculated_home_page has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def calculated_home_page
                          if home_page && !home_page.empty?
                            home_page[URI::regexp(%w(http https))] ? home_page : "http://#{home_page}"
                          elsif request_email_domain
                            "http://www.#{request_email_domain}"
                      Severity: Minor
                      Found in app/models/public_body.rb - About 25 mins 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

                      There are no issues that match your filters.

                      Category
                      Status