otwcode/otwarchive

View on GitHub
app/controllers/challenge_assignments_controller.rb

Summary

Maintainability
C
1 day
Test Coverage

Method update_multiple has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

  def update_multiple
    @errors = []
    params.each_pair do |key, val|
      action, id = key.split(/_/)
      next unless %w(approve default undefault cover).include?(action)
Severity: Minor
Found in app/controllers/challenge_assignments_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

Method index has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

  def index
    if params[:user_id] && (@user = User.find_by(login: params[:user_id]))
      if current_user == @user
        if params[:collection_id] && (@collection = Collection.find_by(name: params[:collection_id]))
          @challenge_assignments = @user.offer_assignments.in_collection(@collection).undefaulted + @user.pinch_hit_assignments.in_collection(@collection).undefaulted
Severity: Minor
Found in app/controllers/challenge_assignments_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

Class ChallengeAssignmentsController has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

class ChallengeAssignmentsController < ApplicationController
  before_action :users_only

  before_action :load_collection, except: [:index]
  before_action :load_challenge, except: [:index]
Severity: Minor
Found in app/controllers/challenge_assignments_controller.rb - About 2 hrs to fix

    Method update_multiple has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def update_multiple
        @errors = []
        params.each_pair do |key, val|
          action, id = key.split(/_/)
          next unless %w(approve default undefault cover).include?(action)
    Severity: Minor
    Found in app/controllers/challenge_assignments_controller.rb - About 1 hr to fix

      Method index has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def index
          if params[:user_id] && (@user = User.find_by(login: params[:user_id]))
            if current_user == @user
              if params[:collection_id] && (@collection = Collection.find_by(name: params[:collection_id]))
                @challenge_assignments = @user.offer_assignments.in_collection(@collection).undefaulted + @user.pinch_hit_assignments.in_collection(@collection).undefaulted
      Severity: Minor
      Found in app/controllers/challenge_assignments_controller.rb - About 1 hr to fix

        There are no issues that match your filters.

        Category
        Status