opennorth/citizen_budget_model

View on GitHub

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)
Severity: Minor
Found in app/models/citizen_budget_model/question.rb - About 3 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

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 }
Severity: Minor
Found in spec/controllers/citizen_budget_model/simulators_controller_spec.rb - About 2 hrs to fix

    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)
    Severity: Minor
    Found in app/models/citizen_budget_model/question.rb - About 1 hr to fix

      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
      Severity: Minor
      Found in db/migrate/20140730020214_create_citizen_budget_model_questions.rb - About 1 hr to fix

        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)
        Severity: Minor
        Found in app/models/citizen_budget_model/question.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

        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
        Severity: Major
        Found in app/models/citizen_budget_model/question.rb - About 40 mins to fix

          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)
          Severity: Minor
          Found in app/controllers/citizen_budget_model/translations_controller.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

          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
          Severity: Minor
          Found in app/models/citizen_budget_model/question.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

          Severity
          Category
          Status
          Source
          Language