app/models/media_resource_modules/filter.rb

Summary

Maintainability
D
1 day
Test Coverage

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) 

        ############################################################
Severity: Minor
Found in app/models/media_resource_modules/filter.rb - About 4 hrs to fix

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
Severity: Minor
Found in app/models/media_resource_modules/filter.rb - About 2 hrs to fix

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) 

        ############################################################
Severity: Major
Found in app/models/media_resource_modules/filter.rb - About 2 hrs to fix

    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}%")
    Severity: Minor
    Found in app/models/media_resource_modules/filter.rb - About 1 hr to fix

    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}%")
    Severity: Minor
    Found in app/models/media_resource_modules/filter.rb - About 1 hr to fix

      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
      Severity: Minor
      Found in app/models/media_resource_modules/filter.rb - About 1 hr to fix

        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
        Severity: Minor
        Found in app/models/media_resource_modules/filter.rb - About 35 mins to fix

        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

        There are no issues that match your filters.

        Category
        Status