discourse/discourse

View on GitHub
lib/topic_query.rb

Summary

Maintainability
F
1 wk
Test Coverage

File topic_query.rb has 844 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class TopicQuery
  PG_MAX_INT ||= 2147483647

  def self.validators
    @validators ||= begin
Severity: Major
Found in lib/topic_query.rb - About 2 days to fix

    Method default_results has a Cognitive Complexity of 78 (exceeds 5 allowed). Consider refactoring.
    Open

      def default_results(options = {})
        options.reverse_merge!(@options)
        options.reverse_merge!(per_page: per_page_setting)
    
        # Whether to return visible topics
    Severity: Minor
    Found in lib/topic_query.rb - About 1 day 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

    Class TopicQuery has 61 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class TopicQuery
      PG_MAX_INT ||= 2147483647
    
      def self.validators
        @validators ||= begin
    Severity: Major
    Found in lib/topic_query.rb - About 1 day to fix

      Method default_results has 145 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def default_results(options = {})
          options.reverse_merge!(@options)
          options.reverse_merge!(per_page: per_page_setting)
      
          # Whether to return visible topics
      Severity: Major
      Found in lib/topic_query.rb - About 5 hrs to fix

        Method list_suggested_for has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
        Open

          def list_suggested_for(topic, pm_params: nil)
        
            # Don't suggest messages unless we have a user, and private messages are
            # enabled.
            return if topic.private_message? &&
        Severity: Minor
        Found in lib/topic_query.rb - About 3 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 private_messages_for has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def private_messages_for(user, type)
            options = @options
            options.reverse_merge!(per_page: per_page_setting)
        
            result = Topic.includes(:tags)
        Severity: Minor
        Found in lib/topic_query.rb - About 1 hr to fix

          Method remove_muted_categories has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

            def remove_muted_categories(list, user, opts = nil)
              category_id = get_category_id(opts[:exclude]) if opts
          
              if user
                list = list
          Severity: Minor
          Found in lib/topic_query.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 prioritize_pinned_topics has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

            def prioritize_pinned_topics(topics, options)
              pinned_clause = if options[:category_id]
                +"topics.category_id = #{options[:category_id].to_i} AND"
              else
                +"pinned_globally AND "
          Severity: Minor
          Found in lib/topic_query.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 apply_ordering has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            def apply_ordering(result, options)
              sort_column = SORTABLE_MAPPING[options[:order]] || 'default'
              sort_dir = (options[:ascending] == "true") ? "ASC" : "DESC"
          
              # If we are sorting in the default order desc, we should consider including pinned
          Severity: Minor
          Found in lib/topic_query.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 create_list has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def create_list(filter, options = {}, topics = nil)
              topics ||= default_results(options)
              topics = yield(topics) if block_given?
          
              options = options.merge(@options)
          Severity: Minor
          Found in lib/topic_query.rb - About 1 hr to fix

            Method list_suggested_for has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def list_suggested_for(topic, pm_params: nil)
            
                # Don't suggest messages unless we have a user, and private messages are
                # enabled.
                return if topic.private_message? &&
            Severity: Minor
            Found in lib/topic_query.rb - About 1 hr to fix

              Method private_messages_for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def private_messages_for(user, type)
                  options = @options
                  options.reverse_merge!(per_page: per_page_setting)
              
                  result = Topic.includes(:tags)
              Severity: Minor
              Found in lib/topic_query.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 create_list has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def create_list(filter, options = {}, topics = nil)
                  topics ||= default_results(options)
                  topics = yield(topics) if block_given?
              
                  options = options.merge(@options)
              Severity: Minor
              Found in lib/topic_query.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 get_pm_params has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def get_pm_params(topic)
                  if topic.private_message?
              
                    my_group_ids = topic.topic_allowed_groups
                      .joins("
              Severity: Minor
              Found in lib/topic_query.rb - About 1 hr to fix

                Method allowed_messages has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def allowed_messages(messages, params)
                    user_ids = (params[:target_user_ids] || [])
                    group_ids = ((params[:target_group_ids] - params[:my_group_ids]) || [])
                
                    if user_ids.present?
                Severity: Minor
                Found in lib/topic_query.rb - About 1 hr to fix

                  Method remove_muted_categories has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def remove_muted_categories(list, user, opts = nil)
                      category_id = get_category_id(opts[:exclude]) if opts
                  
                      if user
                        list = list
                  Severity: Minor
                  Found in lib/topic_query.rb - About 1 hr to fix

                    Method remove_muted_tags has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def remove_muted_tags(list, user, opts = nil)
                        if user.nil? || !SiteSetting.tagging_enabled || SiteSetting.remove_muted_tags_from_latest == 'never'
                          return list
                        end
                    
                    
                    Severity: Minor
                    Found in lib/topic_query.rb - About 1 hr to fix

                      Method remove_muted_tags has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def remove_muted_tags(list, user, opts = nil)
                          if user.nil? || !SiteSetting.tagging_enabled || SiteSetting.remove_muted_tags_from_latest == 'never'
                            return list
                          end
                      
                      
                      Severity: Minor
                      Found in lib/topic_query.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 unread_results has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def unread_results(options = {})
                          result = TopicQuery.unread_filter(
                              default_results(options.reverse_merge(unordered: true)),
                              @user&.id,
                              staff: @user&.staff?)
                      Severity: Minor
                      Found in lib/topic_query.rb - About 45 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 random_suggested has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def random_suggested(topic, count, excluded_topic_ids = [])
                          result = default_results(unordered: true, per_page: count).where(closed: false, archived: false)
                      
                          if SiteSetting.limit_suggested_to_category
                            excluded_topic_ids += Category.where(id: topic.category_id).pluck(:id)
                      Severity: Minor
                      Found in lib/topic_query.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

                      Method allowed_messages has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def allowed_messages(messages, params)
                          user_ids = (params[:target_user_ids] || [])
                          group_ids = ((params[:target_group_ids] - params[:my_group_ids]) || [])
                      
                          if user_ids.present?
                      Severity: Minor
                      Found in lib/topic_query.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

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

                        def list_related_for(topic, pm_params: nil)
                          return if !topic.private_message?
                          return if @user.blank?
                          return if !SiteSetting.enable_personal_messages?
                      
                      
                      Severity: Minor
                      Found in lib/topic_query.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