File application_controller.rb
has 299 lines of code (exceeds 250 allowed). Consider refactoring. Open
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :maintenance_mode?
Method render_error
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def render_error(exception)
# use the exception_notifier gem to send out an e-mail
# to the notification list specified in config/environment.rb
ExceptionNotifier.notify_exception(exception, env: request.env,
data: {
- Read upRead up
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 ApplicationController
has 23 methods (exceeds 20 allowed). Consider refactoring. Open
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :maintenance_mode?
Method authorize_user_for_course
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def authorize_user_for_course
redirect_to(root_path) && return if current_user.nil?
uid = current_user.id
# don't allow sudoing across courses
Method authorize_user_for_course
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def authorize_user_for_course
redirect_to(root_path) && return if current_user.nil?
uid = current_user.id
# don't allow sudoing across courses
- Read upRead up
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_auth_level
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def self.action_auth_level(action, level)
raise ArgumentError, "The action must be specified." if action.nil?
raise ArgumentError, "The action must be symbol." unless action.is_a? Symbol
raise ArgumentError, "The level must be specified." if level.nil?
raise ArgumentError, "The level must be symbol." unless level.is_a? Symbol
- Read upRead up
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 run_scheduler
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run_scheduler
current_time = Time.current
actions = Scheduler.where("next < ? AND ? <= until AND disabled is false", current_time,
current_time)
actions.each do |action|
Method set_submission
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def set_submission
begin
@submission = @assessment.submissions.find(params[:submission_id] || params[:id])
rescue StandardError
flash[:error] = "Could not find submission with id #{params[:submission_id] || params[:id]}."
- Read upRead up
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 authenticate_for_action
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def authenticate_for_action
controller_whitelist = @@global_whitelist[params[:controller].to_sym]
return if controller_whitelist.nil?
level = controller_whitelist[params[:action].to_sym]
- Read upRead up
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 set_course
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def set_course
course_name = params[:course_name] ||
(params[:controller] == "courses" ? params[:name] : nil)
@course = Course.find_by(name: course_name) if course_name
- Read upRead up
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 method. Open
redirect_to([:edit, @course, @cud]) && return
Avoid too many return
statements within this method. Open
return unless (invalid_cud || nicknameless_student) && !in_edit_or_unsudo
Method maintenance_mode?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def maintenance_mode?
# enable/disable maintenance mode with this switch:
return unless ENV["AUTOLAB_MAINTENANCE"]
render(:maintenance) && return unless user_signed_in? && current_user.administrator?
end
- Read upRead up
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"