Noosfero/noosfero

View on GitHub
plugins/pg_search/lib/pg_search_plugin.rb

Summary

Maintainability
D
2 days
Test Coverage

Class PgSearchPlugin has 36 methods (exceeds 20 allowed). Consider refactoring.
Open

class PgSearchPlugin < Noosfero::Plugin
  include SearchHelper

  def self.plugin_name
    "Postgres Full-Text Search"
Severity: Minor
Found in plugins/pg_search/lib/pg_search_plugin.rb - About 4 hrs to fix

    Method filter_by_facets has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def filter_by_facets(scope, facets)
          queries = []
          facets.each do |term, values|
            kind, klass = term.split("-")
            if kind == "attribute" || kind == "relation" || kind == "metadata"
    Severity: Minor
    Found in plugins/pg_search/lib/pg_search_plugin.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

    File pg_search_plugin.rb has 278 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require "noosfero/friendly_mime"
    
    class PgSearchPlugin < Noosfero::Plugin
      include SearchHelper
    
    
    Severity: Minor
    Found in plugins/pg_search/lib/pg_search_plugin.rb - About 2 hrs to fix

      Method active_filters has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def active_filters(asset, scope, params, query = nil)
            facets  = params[:facets] || {}
            periods = (params[:periods] || default_periods_for(asset)).to_h
            query ||= params[:query] || params[:q]
            block = Block.find_by id: params[:block]
      Severity: Minor
      Found in plugins/pg_search/lib/pg_search_plugin.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_by_periods has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def filter_by_periods(scope, periods)
            periods.each do |attribute, period|
              next if period.blank?
      
              if !period["is_metadata"].blank? && period["is_metadata"] == "true"
      Severity: Minor
      Found in plugins/pg_search/lib/pg_search_plugin.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 profile_search_block_extra_content has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def profile_search_block_extra_content(block, params)
          if block.advanced_search
            if params[:controller] == "profile_search"
              # Load facets and periods
              load_facets = true
      Severity: Minor
      Found in plugins/pg_search/lib/pg_search_plugin.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 generic_facet has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def generic_facet(klass, scope, selected_facets, kind, params = {})
            no_results = false
            results = self.send("#{kind}_results", klass, scope, params)
            if results.blank?
              no_results = true
      Severity: Minor
      Found in plugins/pg_search/lib/pg_search_plugin.rb - About 55 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

      Method generic_facet has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def generic_facet(klass, scope, selected_facets, kind, params = {})
      Severity: Minor
      Found in plugins/pg_search/lib/pg_search_plugin.rb - About 35 mins to fix

        Method register_search_facet_occurrence has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def register_search_facet_occurrence(environment, asset, kind, facet_slug, argument)
        Severity: Minor
        Found in plugins/pg_search/lib/pg_search_plugin.rb - About 35 mins to fix

          Method find_by_contents has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def find_by_contents(asset, scope, query, paginate_options = {}, params = {})
          Severity: Minor
          Found in plugins/pg_search/lib/pg_search_plugin.rb - About 35 mins to fix

            Method attribute_option_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def attribute_option_name(name, klass, params)
                  return nil if name.blank?
            
                  if params[:attribute].to_s == "content_type"
                    Noosfero::FriendlyMIME.find(name)[1..-1].upcase
            Severity: Minor
            Found in plugins/pg_search/lib/pg_search_plugin.rb - About 25 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