discourse/discourse

View on GitHub
lib/topic_query.rb

Summary

Maintainability
F
1 wk
Test Coverage

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

require_dependency 'topic_list'
require_dependency 'suggested_topics_builder'
require_dependency 'topic_query_sql'
require_dependency 'avatar_lookup'

Severity: Major
Found in lib/topic_query.rb - About 1 day to fix

    Method default_results has a Cognitive Complexity of 75 (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 56 methods (exceeds 20 allowed). Consider refactoring.
    Open

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

      Method default_results has 149 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 26 (exceeds 5 allowed). Consider refactoring.
        Open

          def list_suggested_for(topic)
        
            # 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 list_suggested_for has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def list_suggested_for(topic)
        
            # 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 2 hrs to fix

          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_tags has a Cognitive Complexity of 14 (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
                  list
                else
                  if !TagUser.lookup(user, :muted).exists?
            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 = options[:category_id] ? "topics.category_id = #{options[:category_id].to_i} AND" : "pinned_globally AND "
                pinned_clause << " pinned_at IS NOT NULL "
                if @user
                  pinned_clause << " AND (topics.pinned_at > tu.cleared_pinned_at OR tu.cleared_pinned_at IS NULL)"
            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 29 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 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 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 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_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
                      list
                    else
                      if !TagUser.lookup(user, :muted).exists?
                Severity: Minor
                Found in lib/topic_query.rb - About 1 hr to fix

                  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 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 apply_shared_drafts has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def apply_shared_drafts(result, category_id, options)
                      drafts_category_id = SiteSetting.shared_drafts_category.to_i
                      viewing_shared = category_id && category_id == drafts_category_id
                  
                      if guardian.can_create_shared_draft?
                  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