discourse/discourse

View on GitHub
lib/topic_query.rb

Summary

Maintainability
F
6 days
Test Coverage

File topic_query.rb has 685 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 51 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class TopicQuery
    
      def self.public_valid_options
        @public_valid_options ||=
          %i(page
    Severity: Major
    Found in lib/topic_query.rb - About 7 hrs to fix

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

          def list_suggested_for(topic)
            return if topic.private_message? && !@user
        
            builder = SuggestedTopicsBuilder.new(topic)
        
        
        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 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def list_suggested_for(topic)
            return if topic.private_message? && !@user
        
            builder = SuggestedTopicsBuilder.new(topic)
        
        
        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 private_messages_for has 36 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 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 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 create_list has a Cognitive Complexity of 9 (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 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 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

                  There are no issues that match your filters.

                  Category
                  Status