Class ApplicationPolicy
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
Method has_role?
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def has_role?(role)
return false unless logged_in?
return true if roles_in('zooniverse').include?(role)
record_sections.each do |section|
roles = roles_in section
- 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 participant?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def participant?
return false unless logged_in?
Array.wrap(record).each do |r|
return false unless r.users.exists?(id: user.id)
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"
Further reading
Method accessible_section?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def accessible_section?(roles = ['admin'])
return true if zooniverse_admin?
Array.wrap(record).each do |r|
return false unless privileged_sections(*roles).include?(r.section)
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"
Further reading
Method user_roles
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def user_roles
return @_roles if @_roles
return { } unless logged_in?
@_roles = { }
sections = (record_sections + ['zooniverse']).uniq
- 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 record_sections
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def record_sections
sections = Array.wrap(record).collect do |r|
r.section if r.respond_to?(:section)
end.compact.uniq
sections.empty? ? ['zooniverse'] : sections
- 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"