File public_body.rb
has 721 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'csv'
require 'securerandom'
require 'set'
require 'confidence_intervals'
Class PublicBody
has 60 methods (exceeds 20 allowed). Consider refactoring. Open
class PublicBody < ApplicationRecord
include CalculatedHomePage
include Categorisable
include Taggable
include Notable
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
- Read upRead up
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
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)
- Read upRead up
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
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' }
- Read upRead up
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})"
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
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
- Read upRead up
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' }
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)
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 = [])
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 = [])
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
- Read upRead up
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 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
- Read upRead up
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"