app/controllers/concerns/controller_helpers.rb
Method authenticate_user
has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring. Open
Open
def authenticate_user(translation_key: nil, translation_args: {}, flash_type: :error)
translation_key ||= :you_have_to_log_in
# Make absolutely sure the current user is confirmed - mainly for testing
if current_user&.confirmed?
- 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
Consider simplifying this complex logical expression. Open
Open
if session[:return_to].present? || cookies[:return_to].present? || params[:return_to]
# NOTE: This is duplicated in permitted_return_to
target = session[:return_to] || cookies[:return_to] || params[:return_to]
session[:return_to] = nil
cookies[:return_to] = nil
Method set_period
has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring. Open
Open
def set_period
@timezone ||= Time.zone
# Set time period
@period ||= params[:period]
if @period == "custom"
- 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
Open
redirect_to(discourse_authentication_url) && (return true)
Avoid too many return
statements within this method. Open
Open
redirect_to(new_session_url(partner: sign_in_partner)) && return