ece517-p3/expertiza

View on GitHub
app/controllers/response_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

Assignment Branch Condition size for create is too high. [60.2/15]
Open

  def create
    map_id = params[:id]
    map_id = params[:map_id] unless params[:map_id].nil? # pass map_id as a hidden field in the review form
    @map = ResponseMap.find(map_id)
    if params[:review][:questionnaire_id]

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

  def redirect
    flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty?
    flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty?
    @map = Response.find_by(map_id: params[:id])
    if params[:return] == "feedback"

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

  def update
    render nothing: true unless action_allowed?
    # the response to be updated
    @response = Response.find(params[:id])
    msg = ""

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

  def save
    @map = ResponseMap.find(params[:id])
    @return = params[:return]
    @map.save
    participant = Participant.find_by(id: @map.reviewee_id)

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

  def edit_allowed?(map, user_id)
    assignment = map.reviewer.assignment
    # if it is a review response map, all the members of reviewee team should be able to view the reponse (can be done from heat map)
    if map.is_a? ReviewResponseMap
      reviewee_team = AssignmentTeam.find(map.reviewee_id)

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

File response_controller.rb has 308 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ResponseController < ApplicationController
  helper :submitted_content
  helper :file

  def action_allowed?
Severity: Minor
Found in app/controllers/response_controller.rb - About 3 hrs to fix

    Assignment Branch Condition size for pending_surveys is too high. [29.14/15]
    Open

      def pending_surveys
        unless session[:user] # Check for a valid user
          redirect_to '/'
          return
        end

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

      def edit
        assign_instance_vars
        @prev = Response.where(map_id: @map.id)
        @review_scores = @prev.to_a
        if @prev.present?

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

      def new_feedback
        review = Response.find(params[:id]) unless params[:id].nil?
        if review
          reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id: review.map.assignment.id).first
          map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id: reviewer.id).first

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

      def pending_surveys
        unless session[:user] # Check for a valid user
          redirect_to '/'
          return
        end
    Severity: Minor
    Found in app/controllers/response_controller.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

    Assignment Branch Condition size for new is too high. [24.7/15]
    Open

      def new
        assign_instance_vars
        set_content(true)
        @stage = @assignment.get_current_stage(SignedUpTeam.topic_id(@participant.parent_id, @participant.user_id)) if @assignment
        # Because of the autosave feature and the javascript that sync if two reviewing windows are opened

    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

    Class ResponseController has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ResponseController < ApplicationController
      helper :submitted_content
      helper :file
    
      def action_allowed?
    Severity: Minor
    Found in app/controllers/response_controller.rb - About 2 hrs to fix

      Assignment Branch Condition size for show_calibration_results_for_student is too high. [21.54/15]
      Open

        def show_calibration_results_for_student
          calibration_response_map = ReviewResponseMap.find(params[:calibration_response_map_id])
          review_response_map = ReviewResponseMap.find(params[:review_response_map_id])
          @calibration_response = calibration_response_map.response[0]
          @review_response = review_response_map.response[0]

      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 redirect is too high. [11/6]
      Open

        def redirect
          flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty?
          flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty?
          @map = Response.find_by(map_id: params[:id])
          if params[:return] == "feedback"

      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 redirect is too high. [12/7]
      Open

        def redirect
          flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty?
          flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty?
          @map = Response.find_by(map_id: params[:id])
          if params[:return] == "feedback"

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

        def create_answers(params, questions)
          # create score if it is not found. If it is found update it otherwise update it
          params[:responses].each_pair do |k, v|
            score = Answer.where(response_id: @response.id, question_id: questions[k.to_i].id).first
            score ||= Answer.create(response_id: @response.id, question_id: questions[k.to_i].id, answer: v[:score], comments: v[:comment])

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

        def action_allowed?
          response = user_id = nil
          action = params[:action]
          if %w[edit delete update view].include?(action)
            response = Response.find(params[:id])

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

        def assign_instance_vars
          case params[:action]
          when 'edit'
            @header = 'Edit'
            @next_action = 'update'

      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

      Perceived complexity for create is too high. [10/7]
      Open

        def create
          map_id = params[:id]
          map_id = params[:map_id] unless params[:map_id].nil? # pass map_id as a hidden field in the review form
          @map = ResponseMap.find(map_id)
          if params[:review][:questionnaire_id]

      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

      Cyclomatic complexity for update is too high. [9/6]
      Open

        def update
          render nothing: true unless action_allowed?
          # the response to be updated
          @response = Response.find(params[:id])
          msg = ""

      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.

      Cyclomatic complexity for create is too high. [9/6]
      Open

        def create
          map_id = params[:id]
          map_id = params[:map_id] unless params[:map_id].nil? # pass map_id as a hidden field in the review form
          @map = ResponseMap.find(map_id)
          if params[:review][:questionnaire_id]

      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.

      Cyclomatic complexity for pending_surveys is too high. [8/6]
      Open

        def pending_surveys
          unless session[:user] # Check for a valid user
            redirect_to '/'
            return
          end

      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 update is too high. [9/7]
      Open

        def update
          render nothing: true unless action_allowed?
          # the response to be updated
          @response = Response.find(params[:id])
          msg = ""

      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

      Cyclomatic complexity for edit_allowed? is too high. [8/6]
      Open

        def edit_allowed?(map, user_id)
          assignment = map.reviewer.assignment
          # if it is a review response map, all the members of reviewee team should be able to view the reponse (can be done from heat map)
          if map.is_a? ReviewResponseMap
            reviewee_team = AssignmentTeam.find(map.reviewee_id)

      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 edit_allowed? is too high. [9/7]
      Open

        def edit_allowed?(map, user_id)
          assignment = map.reviewer.assignment
          # if it is a review response map, all the members of reviewee team should be able to view the reponse (can be done from heat map)
          if map.is_a? ReviewResponseMap
            reviewee_team = AssignmentTeam.find(map.reviewee_id)

      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

      Cyclomatic complexity for action_allowed? is too high. [7/6]
      Open

        def action_allowed?
          response = user_id = nil
          action = params[:action]
          if %w[edit delete update view].include?(action)
            response = Response.find(params[:id])

      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 pending_surveys is too high. [8/7]
      Open

        def pending_surveys
          unless session[:user] # Check for a valid user
            redirect_to '/'
            return
          end

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

        def set_content(new_response = false)
          @title = @map.get_title
          if @map.survey?
            @survey_parent = @map.survey_parent
          else

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

        def redirect
          flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty?
          flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty?
          @map = Response.find_by(map_id: params[:id])
          if params[:return] == "feedback"
      Severity: Minor
      Found in app/controllers/response_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 create has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def create
          map_id = params[:id]
          map_id = params[:map_id] unless params[:map_id].nil? # pass map_id as a hidden field in the review form
          @map = ResponseMap.find(map_id)
          if params[:review][:questionnaire_id]
      Severity: Minor
      Found in app/controllers/response_controller.rb - About 1 hr to fix

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

          def edit
            assign_instance_vars
            @prev = Response.where(map_id: @map.id)
            @review_scores = @prev.to_a
            if @prev.present?
        Severity: Minor
        Found in app/controllers/response_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 pending_surveys has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def pending_surveys
            unless session[:user] # Check for a valid user
              redirect_to '/'
              return
            end
        Severity: Minor
        Found in app/controllers/response_controller.rb - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

              if map.is_a? ReviewResponseMap
                reviewee_team = AssignmentTeam.find(map.reviewee_id)
                return current_user_id?(user_id) || reviewee_team.user?(current_user) || current_user.role.name == 'Administrator' ||
                  (current_user.role.name == 'Instructor' and assignment.instructor_id == current_user.id) ||
                  (current_user.role.name == 'Teaching Assistant' and TaMapping.exists?(ta_id: current_user.id, course_id: assignment.course.id))
          Severity: Major
          Found in app/controllers/response_controller.rb - About 1 hr to fix

            Method create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def create
                map_id = params[:id]
                map_id = params[:map_id] unless params[:map_id].nil? # pass map_id as a hidden field in the review form
                @map = ResponseMap.find(map_id)
                if params[:review][:questionnaire_id]
            Severity: Minor
            Found in app/controllers/response_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

            Method update has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def update
                render nothing: true unless action_allowed?
                # the response to be updated
                @response = Response.find(params[:id])
                msg = ""
            Severity: Minor
            Found in app/controllers/response_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

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

              def action_allowed?
                response = user_id = nil
                action = params[:action]
                if %w[edit delete update view].include?(action)
                  response = Response.find(params[:id])
            Severity: Minor
            Found in app/controllers/response_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 save has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def save
                @map = ResponseMap.find(params[:id])
                @return = params[:return]
                @map.save
                participant = Participant.find_by(id: @map.reviewee_id)
            Severity: Minor
            Found in app/controllers/response_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 edit_allowed? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def edit_allowed?(map, user_id)
                assignment = map.reviewer.assignment
                # if it is a review response map, all the members of reviewee team should be able to view the reponse (can be done from heat map)
                if map.is_a? ReviewResponseMap
                  reviewee_team = AssignmentTeam.find(map.reviewee_id)
            Severity: Minor
            Found in app/controllers/response_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 new_feedback has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def new_feedback
                review = Response.find(params[:id]) unless params[:id].nil?
                if review
                  reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id: review.map.assignment.id).first
                  map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id: reviewer.id).first
            Severity: Minor
            Found in app/controllers/response_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

            Avoid using update_attribute because it skips validations.
            Open

                  score.update_attribute('comments', v[:comment])

            This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations

            Example:

            # bad
            Article.first.decrement!(:view_count)
            DiscussionBoard.decrement_counter(:post_count, 5)
            Article.first.increment!(:view_count)
            DiscussionBoard.increment_counter(:post_count, 5)
            person.toggle :active
            product.touch
            Billing.update_all("category = 'authorized', author = 'David'")
            user.update_attribute(website: 'example.com')
            user.update_columns(last_request_at: Time.current)
            Post.update_counters 5, comment_count: -1, action_count: 1
            
            # good
            user.update_attributes(website: 'example.com')
            FileUtils.touch('file')

            Avoid using update_attribute because it skips validations.
            Open

                  @response.update_attribute('additional_comment', params[:review][:comments])

            This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations

            Example:

            # bad
            Article.first.decrement!(:view_count)
            DiscussionBoard.decrement_counter(:post_count, 5)
            Article.first.increment!(:view_count)
            DiscussionBoard.increment_counter(:post_count, 5)
            person.toggle :active
            product.touch
            Billing.update_all("category = 'authorized', author = 'David'")
            user.update_attribute(website: 'example.com')
            user.update_columns(last_request_at: Time.current)
            Post.update_counters 5, comment_count: -1, action_count: 1
            
            # good
            user.update_attributes(website: 'example.com')
            FileUtils.touch('file')

            Avoid using update_attribute because it skips validations.
            Open

                  @response.update_attribute('is_submitted', true) if params['isSubmit'] && params['isSubmit'] == 'Yes'

            This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations

            Example:

            # bad
            Article.first.decrement!(:view_count)
            DiscussionBoard.decrement_counter(:post_count, 5)
            Article.first.increment!(:view_count)
            DiscussionBoard.increment_counter(:post_count, 5)
            person.toggle :active
            product.touch
            Billing.update_all("category = 'authorized', author = 'David'")
            user.update_attribute(website: 'example.com')
            user.update_columns(last_request_at: Time.current)
            Post.update_counters 5, comment_count: -1, action_count: 1
            
            # good
            user.update_attributes(website: 'example.com')
            FileUtils.touch('file')

            Avoid using update_attribute because it skips validations.
            Open

                  score.update_attribute('answer', v[:score])

            This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations

            Example:

            # bad
            Article.first.decrement!(:view_count)
            DiscussionBoard.decrement_counter(:post_count, 5)
            Article.first.increment!(:view_count)
            DiscussionBoard.increment_counter(:post_count, 5)
            person.toggle :active
            product.touch
            Billing.update_all("category = 'authorized', author = 'David'")
            user.update_attribute(website: 'example.com')
            user.update_columns(last_request_at: Time.current)
            Post.update_counters 5, comment_count: -1, action_count: 1
            
            # good
            user.update_attributes(website: 'example.com')
            FileUtils.touch('file')

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

                  if @map.is_a? FeedbackResponseMap and params[:review][:good_reviewer_checkbox] == 'on'
                    badge_id = Badge.get_id_from_name('Good Reviewer')
                    AwardedBadge.where(participant_id: participant.id, badge_id: badge_id, approval_status: 0).first_or_create
                  end
            Severity: Minor
            Found in app/controllers/response_controller.rb and 1 other location - About 20 mins to fix
            app/controllers/response_controller.rb on lines 190..193

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

            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

                  if @map.is_a? TeammateReviewResponseMap and params[:review][:good_teammate_checkbox] == 'on'
                    badge_id = Badge.get_id_from_name('Good Teammate')
                    AwardedBadge.where(participant_id: participant.id, badge_id: badge_id, approval_status: 0).first_or_create
                  end
            Severity: Minor
            Found in app/controllers/response_controller.rb and 1 other location - About 20 mins to fix
            app/controllers/response_controller.rb on lines 194..197

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

            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

            Line is too long. [164/160]
            Open

                  create_answers(params, questions) unless params[:responses].nil? # for some rubrics, there might be no questions but only file submission (Dr. Ayala's rubric)

            Ternary operators must not be nested. Prefer if or else constructs instead.
            Open

                  @sorted = @review_scores.sort {|m1, m2| m1.version_num.to_i && m2.version_num.to_i ? m2.version_num.to_i <=> m1.version_num.to_i : (m1.version_num ? -1 : 1) }

            Extra blank line detected.
            Open

            
            
            

            This cops checks for two or more consecutive blank lines.

            Example:

            # bad - It has two empty lines.
            some_method
            # one empty line
            # two empty lines
            some_method
            
            # good
            some_method
            # one empty line
            some_method

            Do not use Time.now without zone. Use one of Time.zone.now, Time.current, Time.now.in_time_zone, Time.now.utc, Time.now.getlocal, Time.now.iso8601, Time.now.jisx0301, Time.now.rfc3339, Time.now.to_i, Time.now.to_f instead.
            Open

                      next unless survey_deployment && Time.now > survey_deployment.start_date && Time.now < survey_deployment.end_date

            This cop checks for the use of Time methods without zone.

            Built on top of Ruby on Rails style guide (https://github.com/bbatsov/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/ .

            Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.

            When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.

            Example:

            # always offense
            Time.now
            Time.parse('2015-03-02 19:05:37')
            
            # no offense
            Time.zone.now
            Time.zone.parse('2015-03-02 19:05:37')
            
            # no offense only if style is 'flexible'
            Time.current
            DateTime.strptime(str, "%Y-%m-%d %H:%M %Z").in_time_zone
            Time.at(timestamp).in_time_zone

            Use empty lines between method definitions.
            Open

              def update

            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

            Do not prefix writer method names with set_.
            Open

              def set_content(new_response = false)

            This cop makes sure that accessor methods are named properly.

            Example:

            # bad
            def set_attribute(value)
            end
            
            # good
            def attribute=(value)
            end
            
            # bad
            def get_attribute
            end
            
            # good
            def attribute
            end

            Do not use Time.now without zone. Use one of Time.zone.now, Time.current, Time.now.in_time_zone, Time.now.utc, Time.now.getlocal, Time.now.iso8601, Time.now.jisx0301, Time.now.rfc3339, Time.now.to_i, Time.now.to_f instead.
            Open

                      next unless survey_deployment && Time.now > survey_deployment.start_date && Time.now < survey_deployment.end_date

            This cop checks for the use of Time methods without zone.

            Built on top of Ruby on Rails style guide (https://github.com/bbatsov/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/ .

            Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.

            When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.

            Example:

            # always offense
            Time.now
            Time.parse('2015-03-02 19:05:37')
            
            # no offense
            Time.zone.now
            Time.zone.parse('2015-03-02 19:05:37')
            
            # no offense only if style is 'flexible'
            Time.current
            DateTime.strptime(str, "%Y-%m-%d %H:%M %Z").in_time_zone
            Time.at(timestamp).in_time_zone

            Line is too long. [164/160]
            Open

                  @sorted = @review_scores.sort {|m1, m2| m1.version_num.to_i && m2.version_num.to_i ? m2.version_num.to_i <=> m1.version_num.to_i : (m1.version_num ? -1 : 1) }

            Useless assignment to variable - was_submitted.
            Open

                was_submitted = false

            This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

            assigned but unused variable - foo

            Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

            Example:

            # bad
            
            def some_method
              some_var = 1
              do_something
            end

            Example:

            # good
            
            def some_method
              some_var = 1
              do_something(some_var)
            end

            Line is too long. [161/160]
            Open

                @assignment_questionnaire = AssignmentQuestionnaire.where(["assignment_id = ? and questionnaire_id IN (?)", @assignment.id, @review_questionnaire_ids]).first

            Extra blank line detected.
            Open

            
              # Update the response and answers when student "edit" existing response

            This cops checks for two or more consecutive blank lines.

            Example:

            # bad - It has two empty lines.
            some_method
            # one empty line
            # two empty lines
            some_method
            
            # good
            some_method
            # one empty line
            some_method

            Line is too long. [176/160]
            Open

                @response.update(additional_comment: params[:review][:comments], is_submitted: is_submitted) # ignore if autoupdate try to save when the response object is not yet created.

            There are no issues that match your filters.

            Category
            Status