Method filter
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
def filter(current_user, filter_opts)
filter_opts = filter_opts.delete_if {|k,v| v.blank?}.deep_symbolize_keys
raise "invalid option" unless filter_opts.is_a?(Hash)
############################################################
- 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 filter_meta_data
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def filter_meta_data(resources, filter)
filter.each_pair do |k,v|
# this is AND implementation
v[:ids].each do |id|
# OPTIMIZE resource.joins(etc...) directly intersecting multiple criteria doesn't work, then we use subqueries
- 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 filter
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
def filter(current_user, filter_opts)
filter_opts = filter_opts.delete_if {|k,v| v.blank?}.deep_symbolize_keys
raise "invalid option" unless filter_opts.is_a?(Hash)
############################################################
Method filter_media_file
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def filter_media_file(options)
sql = media_entries.joins("RIGHT JOIN media_files ON media_resources.id = media_files.media_entry_id")
options[:content_type].each do |x|
sql = sql.where("media_files.content_type ilike ?", "%#{x}%")
- 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 filter_media_file
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def filter_media_file(options)
sql = media_entries.joins("RIGHT JOIN media_files ON media_resources.id = media_files.media_entry_id")
options[:content_type].each do |x|
sql = sql.where("media_files.content_type ilike ?", "%#{x}%")
Method filter_meta_data
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def filter_meta_data(resources, filter)
filter.each_pair do |k,v|
# this is AND implementation
v[:ids].each do |id|
# OPTIMIZE resource.joins(etc...) directly intersecting multiple criteria doesn't work, then we use subqueries
Method filter_permissions
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def filter_permissions(resources, current_user, filter)
filter.each_pair do |k,v|
v[:ids].each do |id|
resources = case k
when :owner
- 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"