roqua/quby_engine

View on GitHub

Showing 107 of 107 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

              case "minimum_checked_required":
                  var checkboxes = question_item.find('input[type=checkbox]:checked');
                  if (checkboxes.length < validation.minimum_checked_value) {
                    pushFailVal(validation.type);
                  }
Severity: Minor
Found in app/assets/javascripts/quby/answers/validation.js and 1 other location - About 35 mins to fix
app/assets/javascripts/quby/answers/validation.js on lines 173..178

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 47.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

              case "maximum_checked_allowed":
                  var checkboxes = question_item.find('input[type=checkbox]:checked');
                  if (checkboxes.length > validation.maximum_checked_value) {
                      pushFailVal(validation.type);
                  }
Severity: Minor
Found in app/assets/javascripts/quby/answers/validation.js and 1 other location - About 35 mins to fix
app/assets/javascripts/quby/answers/validation.js on lines 179..184

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 47.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method extra_failed_validations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def extra_failed_validations
          @extra_failed_validations = {}
          questionnaire.questions.each do |q|
            next unless q
            unless q.raw_content.blank?
Severity: Minor
Found in lib/quby/answers/entities/answer.rb - About 35 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 calc_answered has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def calc_answered(qkeys)
          answered = 0
          qkeys.each do |qk|
            ans = send(qk)
            if ans.is_a? Hash # in case of check_box, only count checked check_boxes as answered
Severity: Minor
Found in lib/quby/answers/entities/answer.rb - About 35 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 extra_question_values has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def extra_question_values
          @extra_question_values = {}
          questionnaire.questions.each do |q|
            next unless q
            unless q.raw_content.blank?
Severity: Minor
Found in lib/quby/answers/entities/answer.rb - About 35 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 verify_answer_id_against_session has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def verify_answer_id_against_session
      if Quby::Settings.authorize_with_id_from_session
        fail MissingAuthorizationError unless session[:quby_answer_id].present?
        fail InvalidAuthorizationError unless params[:id].to_s == session[:quby_answer_id].to_s
      end
Severity: Minor
Found in app/controllers/quby/answers_controller.rb - About 35 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

Function activatePanel has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

function activatePanel(panel, forward) {
    if (shownFlash) {
        $('.flash').hide();
    }
    shownFlash = true;
Severity: Minor
Found in app/assets/javascripts/quby/answers/rest.js - About 35 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 make_baseline_proc has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

          def make_baseline_proc
            return unless @baseline

            case @baseline
            when Hash
Severity: Minor
Found in lib/quby/questionnaires/entities/charting/line_chart.rb - About 35 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

Avoid too many return statements within this function.
Open

    return inputs.length == 0;
Severity: Major
Found in app/assets/javascripts/quby/answers/validation.js - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

              return true if question.is_a?(Questionnaires::Entities::Questions::FloatQuestion)   && answer == ""
    Severity: Major
    Found in lib/quby/answers/services/answer_validations.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                return true if parent_option_is_not_selected(question)
      Severity: Major
      Found in lib/quby/answers/services/answer_validations.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                  return true if hidden_questions&.include?(question.key)
        Severity: Major
        Found in lib/quby/answers/services/answer_validations.rb - About 30 mins to fix

          Method validate_each has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def validate_each(record, attribute, value)
              return if value.blank?
              if value.respond_to?(:valid?)
                record.errors.add(attribute, value.errors.full_messages.join(', ')) unless value.valid?
              else
          Severity: Minor
          Found in lib/active_model_modules/attribute_valid_validator.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 mark_completed has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                  def mark_completed(start_time)
                    if completed? || @aborted
                      self.started_at = start_time if started_at.blank?
                      self.completed_at = Time.now if completed_at.blank?
                    end
          Severity: Minor
          Found in lib/quby/answers/entities/answer.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 to_codebook has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                    def to_codebook(questionnaire, opts = {})
                      output = []
                      components.each do |component|
                        output << "#{codebook_key(send("#{component}_key"), questionnaire, opts)} " \
                        "#{type}_#{component} #{codebook_output_range}"
          Severity: Minor
          Found in lib/quby/questionnaires/entities/questions/date_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

          Method validate_not_all_checked has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                  def validate_not_all_checked(question, validation, value)
                    # We have decided not to allow bypassing this validation when
                    # aborted, since it's possible to make a decision about which fields
                    # to keep and which ones to blank. If you want to do anything at all
                    # with this completion, you'll need to decide that at some point
          Severity: Minor
          Found in lib/quby/answers/services/answer_validator.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_to_textvar_values has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def default_to_textvar_values(answer)
                @questionnaire.questions.each do |question|
                  textvar = question.sets_textvar or next
                  if answer.textvars.key?(textvar.to_sym) && !answer.value.key?(question.key.to_s)
                    answer.value[question.key.to_s] ||= answer.textvars[textvar.to_sym]
          Severity: Minor
          Found in app/controllers/quby/answers_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 json_items has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                  def json_items
                    items.map do |item|
                      case item
                      when Text
                        { type: 'html', html: item.html }
          Severity: Minor
          Found in lib/quby/questionnaires/entities/panel.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 update_or_fail has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def update_or_fail
                updater = Answers::Services::UpdatesAnswers.new(@answer)
          
                updater.on_success do
                  yield
          Severity: Minor
          Found in app/controllers/quby/answers_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 validations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                  def validations
                    vals = {}
                    items.each do |item|
                      if item.is_a? Question
                        item.options.each do |opt|
          Severity: Minor
          Found in lib/quby/questionnaires/entities/panel.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