mysociety/alaveteli

View on GitHub
app/models/public_body.rb

Summary

Maintainability
F
5 days
Test Coverage

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

    class PublicBody < ApplicationRecord
      include CalculatedHomePage
      include Categorisable
      include Taggable
      include Notable
    Severity: Major
    Found in app/models/public_body.rb - About 1 day to fix

      Method import_csv_from_file has a Cognitive Complexity of 36 (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 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 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 with_query has 43 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 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 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 = AlaveteliLocalization.
                  with_locale(AlaveteliLocalization.default_locale) do
                  default_scoped.where(url_name: 'internal_admin_authority')
                end
            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)
                    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 30 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 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 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 internal_admin_body has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def self.internal_admin_body
                          matching_pbs = AlaveteliLocalization.
                            with_locale(AlaveteliLocalization.default_locale) do
                            default_scoped.where(url_name: 'internal_admin_authority')
                          end
                      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