expertiza/expertiza

View on GitHub
app/controllers/questions_controller.rb

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

Class has too many lines. [115/100]
Open

class QuestionsController < ApplicationController
  include AuthorizationHelper

  # A question is a single entry within a questionnaire
  # Questions provide a way of scoring an object

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for save_questions is too high. [29.31/15]
Open

  def save_questions
    questionnaire_id = params[:questionnaire_id]
    questionnaire_type = params[:questionnaire_type]
    delete_questions questionnaire_id
    save_new_questions(questionnaire_id, questionnaire_type)

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for save_new_questions is too high. [26.13/15]
Open

  def save_new_questions(questionnaire_id, questionnaire_type)
    if params[:new_question]
      # The new_question array contains all the new questions
      # that should be saved to the database
      params[:new_question].keys.each_with_index do |question_key, index|

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [15/10]
Open

  def delete_questions(questionnaire_id)
    # Deletes any questions that, as a result of the edit, are no longer in the questionnaire
    questions = Question.where('questionnaire_id = ?', questionnaire_id)
    @deleted_questions = []
    questions.each do |question|

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [15/10]
Open

  def save_questions
    questionnaire_id = params[:questionnaire_id]
    questionnaire_type = params[:questionnaire_type]
    delete_questions questionnaire_id
    save_new_questions(questionnaire_id, questionnaire_type)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [15/10]
Open

  def save_new_questions(questionnaire_id, questionnaire_type)
    if params[:new_question]
      # The new_question array contains all the new questions
      # that should be saved to the database
      params[:new_question].keys.each_with_index do |question_key, index|

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [13/10]
Open

  def destroy
    question = Question.find(params[:id])
    questionnaire_id = question.questionnaire_id

    if AnswerHelper.check_and_delete_responses(questionnaire_id)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for delete_questions is too high. [15.81/15]
Open

  def delete_questions(questionnaire_id)
    # Deletes any questions that, as a result of the edit, are no longer in the questionnaire
    questions = Question.where('questionnaire_id = ?', questionnaire_id)
    @deleted_questions = []
    questions.each do |question|

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method delete_questions has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def delete_questions(questionnaire_id)
    # Deletes any questions that, as a result of the edit, are no longer in the questionnaire
    questions = Question.where('questionnaire_id = ?', questionnaire_id)
    @deleted_questions = []
    questions.each do |question|
Severity: Minor
Found in app/controllers/questions_controller.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 save_questions has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def save_questions
    questionnaire_id = params[:questionnaire_id]
    questionnaire_type = params[:questionnaire_type]
    delete_questions questionnaire_id
    save_new_questions(questionnaire_id, questionnaire_type)
Severity: Minor
Found in app/controllers/questions_controller.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 save_new_questions has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def save_new_questions(questionnaire_id, questionnaire_type)
    if params[:new_question]
      # The new_question array contains all the new questions
      # that should be saved to the database
      params[:new_question].keys.each_with_index do |question_key, index|
Severity: Minor
Found in app/controllers/questions_controller.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

Use each_key instead of keys.each.
Open

      params[:question].keys.each do |question_key|

This cop checks for uses of each_key and each_value Hash methods.

Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

Example:

# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
hash.each { |k, _v| p k }
hash.each { |_k, v| p v }

# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }

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

        if params[:question][question_key][:txt].strip.empty?
          Question.delete(question_key)
        else
          question = Question.find(question_key)
          Rails.logger.info(question.errors.messages.inspect) unless question.update_attributes(params[:question][question_key])
Severity: Minor
Found in app/controllers/questions_controller.rb and 1 other location - About 30 mins to fix
app/controllers/quiz_questionnaires_controller.rb on lines 242..248

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 33.

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

Keep a blank line before and after private.
Open

  private

Access modifiers should be surrounded by blank lines.

Example:

# bad
class Foo
  def bar; end
  private
  def baz; end
end

# good
class Foo
  def bar; end

  private

  def baz; end
end

Use empty lines between method definitions.
Open

  def save_questions

This cop checks whether method definitions are separated by one empty line.

NumberOfEmptyLines can be and integer (e.g. 1 by default) or an array (e.g. [1, 2]) to specificy a minimum and a maximum of empty lines.

AllowAdjacentOneLineDefs can be used to configure is adjacent one line methods definitions are an offense

Example:

# bad
def a
end
def b
end

Example:

# good
def a
end

def b
end

1 trailing blank lines detected.
Open

Use empty lines between method definitions.
Open

  def delete_questions(questionnaire_id)

This cop checks whether method definitions are separated by one empty line.

NumberOfEmptyLines can be and integer (e.g. 1 by default) or an array (e.g. [1, 2]) to specificy a minimum and a maximum of empty lines.

AllowAdjacentOneLineDefs can be used to configure is adjacent one line methods definitions are an offense

Example:

# bad
def a
end
def b
end

Example:

# good
def a
end

def b
end

Missing top-level class documentation comment.
Open

class QuestionsController < ApplicationController

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Redundant return detected.
Open

    return

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Redundant return detected.
Open

    return

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Redundant return detected.
Open

    return

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

There are no issues that match your filters.

Category
Status