expertiza/expertiza

View on GitHub
app/models/response.rb

Summary

Maintainability
C
7 hrs
Test Coverage
F
25%

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

class Response < ApplicationRecord
  # Added for E1973. A team review will have a lock on it so only one user at a time may edit it.
  include Lockable
  include ResponseAnalytic
  include Scoring
Severity: Minor
Found in app/models/response.rb by rubocop

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 notify_instructor_on_difference is too high. [33.96/15]
Open

  def notify_instructor_on_difference
    response_map = map
    reviewer_participant_id = response_map.reviewer_id
    reviewer_participant = AssignmentParticipant.find(reviewer_participant_id)
    reviewer_name = User.find(reviewer_participant.user_id).fullname
Severity: Minor
Found in app/models/response.rb by rubocop

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 concatenate_all_review_comments is too high. [30.55/15]
Open

  def self.concatenate_all_review_comments(assignment_id, reviewer_id)
    comments = ''
    counter = 0
    @comments_in_round = []
    @counter_in_round = []
Severity: Minor
Found in app/models/response.rb by rubocop

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. [24/10]
Open

  def self.concatenate_all_review_comments(assignment_id, reviewer_id)
    comments = ''
    counter = 0
    @comments_in_round = []
    @counter_in_round = []
Severity: Minor
Found in app/models/response.rb by rubocop

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. [22/10]
Open

  def notify_instructor_on_difference
    response_map = map
    reviewer_participant_id = response_map.reviewer_id
    reviewer_participant = AssignmentParticipant.find(reviewer_participant_id)
    reviewer_name = User.find(reviewer_participant.user_id).fullname
Severity: Minor
Found in app/models/response.rb by rubocop

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 significant_difference? is too high. [26.94/15]
Open

  def significant_difference?
    map_class = map.class
    existing_responses = map_class.assessments_for(map.reviewee)
    average_score_on_same_artifact_from_others, count = Response.avg_scores_and_count_for_prev_reviews(existing_responses, self)
    # if this response is the first on this artifact, there's no grade conflict
Severity: Minor
Found in app/models/response.rb by rubocop

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 add_table_rows is too high. [26.57/15]
Open

  def add_table_rows(questionnaire_max, questions, answers, code, tag_prompt_deployments = nil, current_user = nil)
    count = 0
    # loop through questions so the the questions are displayed in order based on seq (sequence number)
    questions.each do |question|
      count += 1 if !question.is_a?(QuestionnaireHeader) && (question.break_before == true)
Severity: Minor
Found in app/models/response.rb by rubocop

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 construct_review_response is too high. [26.59/15]
Open

  def construct_review_response(code, self_id, show_tags = nil, current_user = nil)
    code += '<table id="review_' + self_id + '" class="table table-bordered">'
    answers = Answer.where(response_id: response_id)
    unless answers.empty?
      questionnaire = questionnaire_by_answer(answers.first)
Severity: Minor
Found in app/models/response.rb by rubocop

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. [19/10]
Open

  def add_table_rows(questionnaire_max, questions, answers, code, tag_prompt_deployments = nil, current_user = nil)
    count = 0
    # loop through questions so the the questions are displayed in order based on seq (sequence number)
    questions.each do |question|
      count += 1 if !question.is_a?(QuestionnaireHeader) && (question.break_before == true)
Severity: Minor
Found in app/models/response.rb by rubocop

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. [17/10]
Open

  def construct_review_response(code, self_id, show_tags = nil, current_user = nil)
    code += '<table id="review_' + self_id + '" class="table table-bordered">'
    answers = Answer.where(response_id: response_id)
    unless answers.empty?
      questionnaire = questionnaire_by_answer(answers.first)
Severity: Minor
Found in app/models/response.rb by rubocop

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 volume_of_review_comments is too high. [22.05/15]
Open

  def self.volume_of_review_comments(assignment_id, reviewer_id)
    comments, counter,
      @comments_in_round, @counter_in_round = Response.concatenate_all_review_comments(assignment_id, reviewer_id)
    num_rounds = @comments_in_round.count - 1 # ignore nil element (index 0)

Severity: Minor
Found in app/models/response.rb by rubocop

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

Cyclomatic complexity for add_table_rows is too high. [12/6]
Open

  def add_table_rows(questionnaire_max, questions, answers, code, tag_prompt_deployments = nil, current_user = nil)
    count = 0
    # loop through questions so the the questions are displayed in order based on seq (sequence number)
    questions.each do |question|
      count += 1 if !question.is_a?(QuestionnaireHeader) && (question.break_before == true)
Severity: Minor
Found in app/models/response.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Perceived complexity for add_table_rows is too high. [13/7]
Open

  def add_table_rows(questionnaire_max, questions, answers, code, tag_prompt_deployments = nil, current_user = nil)
    count = 0
    # loop through questions so the the questions are displayed in order based on seq (sequence number)
    questions.each do |question|
      count += 1 if !question.is_a?(QuestionnaireHeader) && (question.break_before == true)
Severity: Minor
Found in app/models/response.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Assignment Branch Condition size for construct_instructor_html is too high. [19.42/15]
Open

  def construct_instructor_html(identifier, self_id, count)
    identifier += '<h4><B>Review ' + count.to_s + '</B></h4>'
    identifier += '<B>Reviewer: </B>' + map.reviewer.fullname + ' (' + map.reviewer.name + ')'
    identifier + '&nbsp;&nbsp;&nbsp;<a href="#" name= "review_' + self_id + 'Link" onClick="toggleElement(' \
           "'review_" + self_id + "','review'" + ');return false;">hide review</a><BR/>'
Severity: Minor
Found in app/models/response.rb by rubocop

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 add_table_rows has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  def add_table_rows(questionnaire_max, questions, answers, code, tag_prompt_deployments = nil, current_user = nil)
    count = 0
    # loop through questions so the the questions are displayed in order based on seq (sequence number)
    questions.each do |question|
      count += 1 if !question.is_a?(QuestionnaireHeader) && (question.break_before == true)
Severity: Minor
Found in app/models/response.rb - About 2 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 response.rb has 251 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'analytic/response_analytic'
require 'lingua/en/readability'

class Response < ApplicationRecord
  # Added for E1973. A team review will have a lock on it so only one user at a time may edit it.
Severity: Minor
Found in app/models/response.rb - About 2 hrs to fix

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

      def self.volume_of_review_comments(assignment_id, reviewer_id)
        comments, counter,
          @comments_in_round, @counter_in_round = Response.concatenate_all_review_comments(assignment_id, reviewer_id)
        num_rounds = @comments_in_round.count - 1 # ignore nil element (index 0)
    
    
    Severity: Minor
    Found in app/models/response.rb by rubocop

    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 maximum_score is too high. [17.97/15]
    Open

      def maximum_score
        # only count the scorable questions, only when the answer is not nil (we accept nil as
        # answer for scorable questions, and they will not be counted towards the total score)
        total_weight = 0
        scores.each do |s|
    Severity: Minor
    Found in app/models/response.rb by rubocop

    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. [12/10]
    Open

      def questionnaire_by_answer(answer)
        if answer.nil?
          # there is small possibility that the answers is empty: when the questionnaire only have 1 question and it is a upload file question
          # the reason is that for this question type, there is no answer record, and this question is handled by a different form
          map = ResponseMap.find(map_id)
    Severity: Minor
    Found in app/models/response.rb by rubocop

    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. [12/10]
    Open

      def email(partial = 'new_submission')
        defn = {}
        defn[:body] = {}
        defn[:body][:partial_name] = partial
        response_map = ResponseMap.find map_id
    Severity: Minor
    Found in app/models/response.rb by rubocop

    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 display_as_html is too high. [16.25/15]
    Open

      def display_as_html(prefix = nil, count = nil, _file_url = nil, show_tags = nil, current_user = nil)
        identifier = ''
        # The following three lines print out the type of rubric before displaying
        # feedback.  Currently this is only done if the rubric is Author Feedback.
        # It doesn't seem necessary to print out the rubric type in the case of
    Severity: Minor
    Found in app/models/response.rb by rubocop

    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. [11/10]
    Open

      def maximum_score
        # only count the scorable questions, only when the answer is not nil (we accept nil as
        # answer for scorable questions, and they will not be counted towards the total score)
        total_weight = 0
        scores.each do |s|
    Severity: Minor
    Found in app/models/response.rb by rubocop

    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. [11/10]
    Open

      def display_as_html(prefix = nil, count = nil, _file_url = nil, show_tags = nil, current_user = nil)
        identifier = ''
        # The following three lines print out the type of rubric before displaying
        # feedback.  Currently this is only done if the rubric is Author Feedback.
        # It doesn't seem necessary to print out the rubric type in the case of
    Severity: Minor
    Found in app/models/response.rb by rubocop

    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 create_or_get_response is too high. [16.03/15]
    Open

      def create_or_get_response(response_map, current_round)
        response = Response.where(map_id: response_map.id, round: current_round.to_i).order(updated_at: :desc).first
        reviewee_team = AssignmentTeam.find_by(id: response_map.reviewee_id)
    
        most_recent_submission_by_reviewee = reviewee_team.most_recent_submission if reviewee_team
    Severity: Minor
    Found in app/models/response.rb by rubocop

    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 concatenate_all_review_comments has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.concatenate_all_review_comments(assignment_id, reviewer_id)
        comments = ''
        counter = 0
        @comments_in_round = []
        @counter_in_round = []
    Severity: Minor
    Found in app/models/response.rb - About 55 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 add_table_rows has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def add_table_rows(questionnaire_max, questions, answers, code, tag_prompt_deployments = nil, current_user = nil)
    Severity: Minor
    Found in app/models/response.rb - About 45 mins to fix

      Method display_as_html has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def display_as_html(prefix = nil, count = nil, _file_url = nil, show_tags = nil, current_user = nil)
      Severity: Minor
      Found in app/models/response.rb - About 35 mins to fix

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

          def construct_review_response(code, self_id, show_tags = nil, current_user = nil)
            code += '<table id="review_' + self_id + '" class="table table-bordered">'
            answers = Answer.where(response_id: response_id)
            unless answers.empty?
              questionnaire = questionnaire_by_answer(answers.first)
        Severity: Minor
        Found in app/models/response.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 maximum_score has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def maximum_score
            # only count the scorable questions, only when the answer is not nil (we accept nil as
            # answer for scorable questions, and they will not be counted towards the total score)
            total_weight = 0
            scores.each do |s|
        Severity: Minor
        Found in app/models/response.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

        Avoid parameter lists longer than 5 parameters. [6/5]
        Open

          def add_table_rows(questionnaire_max, questions, answers, code, tag_prompt_deployments = nil, current_user = nil)
        Severity: Minor
        Found in app/models/response.rb by rubocop

        This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

        TODO found
        Open

          # TODO: change metareview_response_map relationship to belongs_to
        Severity: Minor
        Found in app/models/response.rb by fixme

        Missing top-level class documentation comment.
        Open

        class Response < ApplicationRecord
        Severity: Minor
        Found in app/models/response.rb by rubocop

        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

        There are no issues that match your filters.

        Category
        Status