Assignment Branch Condition size for login is too high. [19.34/15] Open
def login
if request.get?
AuthController.clear_session(session)
else
user = User.find_by_login(params[:login][:name])
- Read upRead up
- Exclude checks
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 login
if request.get?
AuthController.clear_session(session)
else
user = User.find_by_login(params[:login][:name])
- Read upRead up
- Exclude checks
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 self.clear_user_info(session, assignment_id)
session[:user_id] = nil
session[:user] = '' # sets user to an empty string instead of nil, to show that the user was logged in
role = Role.student
if role
- Read upRead up
- Exclude checks
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 self.set_current_role(role_id, session)
if role_id
role = Role.find(role_id)
if role
Role.rebuild_cache if !role.cache || !role.cache.try(:has_key?, :credentials)
- Read upRead up
- Exclude checks
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 after_login is too high. [15.13/15] Open
def after_login(user)
session[:user] = user
session[:impersonate] = false
ExpertizaLogger.info LoggerMessage.new('', user.name, 'Login successful')
AuthController.set_current_role(user.role_id, session)
- Read upRead up
- Exclude checks
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 set_current_role is too high. [15.81/15] Open
def self.set_current_role(role_id, session)
if role_id
role = Role.find(role_id)
if role
Role.rebuild_cache if !role.cache || !role.cache.try(:has_key?, :credentials)
- Read upRead up
- Exclude checks
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 set_current_role
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def self.set_current_role(role_id, session)
if role_id
role = Role.find(role_id)
if role
Role.rebuild_cache if !role.cache || !role.cache.try(:has_key?, :credentials)
- 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 login
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def login
if request.get?
AuthController.clear_session(session)
else
user = User.find_by_login(params[:login][: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
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if role_id
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Do not place comments on the same line as the end
keyword. Open
end # def login
- Read upRead up
- Exclude checks
This cop checks for comments put on the same line as some keywords.
These keywords are: begin
, class
, def
, end
, module
.
Note that some comments (such as :nodoc:
and rubocop:disable
) are
allowed.
Example:
# bad
if condition
statement
end # end if
# bad
class X # comment
statement
end
# bad
def x; end # comment
# good
if condition
statement
end
# good
class X # :nodoc:
y
end
Missing top-level class documentation comment. Open
class AuthController < ApplicationController
- Read upRead up
- Exclude checks
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