rails/app/models/user.rb
Class User
has 72 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class User < ApplicationRecord
has_many :authentications, :dependent => :delete_all
has_many :access_grants, :dependent => :delete_all
has_many :favorites
File user.rb
has 463 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
require 'digest/sha1'
class User < ApplicationRecord
has_many :authentications, :dependent => :delete_all
has_many :access_grants, :dependent => :delete_all
Method find_for_omniauth
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def find_for_omniauth(auth, signed_in_resource=nil)
authentication = Authentication.find_by_provider_and_uid auth.provider, auth.uid
if authentication
# Since we're not planning to access the provider on behalf of the user,
# don't bother storing tokens for now.
Method is_project_researcher?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def is_project_researcher?(project = nil, allow_expired: false, check_can_manage_permission_forms: false)
target_association = allow_expired ? _project_user_researchers_inc_expired : _project_user_researchers
if check_can_manage_permission_forms
if project
- 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_role_for_projects
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def set_role_for_projects(role, possible_projects, selected_project_ids, expiration_dates={}, can_manage_permission_forms={})
Method find_for_omniauth
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
def find_for_omniauth(auth, signed_in_resource=nil)
authentication = Authentication.find_by_provider_and_uid auth.provider, auth.uid
if authentication
# Since we're not planning to access the provider on behalf of the user,
# don't bother storing tokens for now.
- 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"