src/api/app/models/user.rb
Class User
has 90 methods (exceeds 20 allowed). Consider refactoring. Open
Open
class User < ApplicationRecord
include CanRenderModel
include Flipper::Identifier
# Keep in sync with states defined in db/schema.rb
Method has_local_permission?
has a Cognitive Complexity of 13 (exceeds 8 allowed). Consider refactoring. Open
Open
def has_local_permission?(perm_string, object)
roles = Role.ids_with_permission(perm_string)
return false unless roles
parent = nil
- 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 has_local_permission?
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
def has_local_permission?(perm_string, object)
roles = Role.ids_with_permission(perm_string)
return false unless roles
parent = nil
Method has_local_role?
has a Cognitive Complexity of 10 (exceeds 8 allowed). Consider refactoring. Open
Open
def has_local_role?(role, object)
if object.is_a?(Package) || object.is_a?(Project)
logger.debug "running local role package check: user #{login}, package #{object.name}, role '#{role.title}'"
rels = object.relationships.where(role_id: role.id, user_id: id)
return true if rels.exists?
- 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
return has_local_permission?(perm_string, parent)
Avoid too many return
statements within this method. Open
Open
return true if lookup_strategy.local_permission_check(roles, object)