Showing 8 of 46 total issues
Method set_options
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def set_options
if minimum.present? && maximum.present? && step.present? && step.to_f.nonzero?
if default_value.present?
decimal_minimum = BigDecimal(minimum.to_s)
decimal_maximum = BigDecimal(maximum.to_s)
- 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
File simulators_controller_spec.rb
has 281 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'rails_helper'
module CitizenBudgetModel
RSpec.describe SimulatorsController, type: :controller do
routes { Engine.routes }
Method set_options
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set_options
if minimum.present? && maximum.present? && step.present? && step.to_f.nonzero?
if default_value.present?
decimal_minimum = BigDecimal(minimum.to_s)
decimal_maximum = BigDecimal(maximum.to_s)
Method up
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def up
create_table :citizen_budget_model_questions do |t|
t.belongs_to :section, index: true
# Simulation
Method all_or_none_of_minimum_and_maximum_and_step_should_be_present
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def all_or_none_of_minimum_and_maximum_and_step_should_be_present
unless minimum.present? && maximum.present? && step.present? || minimum.blank? && maximum.blank? && step.blank?
[:minimum, :maximum, :step].each do |attribute|
if send(attribute).blank?
errors.add(attribute, :blank)
- 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
Consider simplifying this complex logical expression. Open
unless minimum.present? && maximum.present? && step.present? || minimum.blank? && maximum.blank? && step.blank?
[:minimum, :maximum, :step].each do |attribute|
if send(attribute).blank?
errors.add(attribute, :blank)
end
Method create
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def create
if params[:pk] && params[:value]
locale, key = params[:pk].split('.', 2)
if I18n.backend.exists?(I18n.default_locale, key)
I18n.backend.store_translations(locale, {key => params[:value]}, :escape => false)
- 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 default_value_must_be_an_option
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def default_value_must_be_an_option
if options.present? && default_value.present?
unless options.include?(default_value) || options.include?(default_value.to_f)
errors.add(:default_value, _('must be a valid option'))
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"