discourse/discourse

View on GitHub

Showing 1,411 of 1,710 total issues

Method default_results has 150 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 6 hrs to fix

    File 006_badges.rb has 416 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'badge_queries'
    
    BadgeGrouping.seed do |g|
      g.id = BadgeGrouping::GettingStarted
      g.name = "Getting Started"
    Severity: Minor
    Found in db/fixtures/006_badges.rb - About 6 hrs to fix

      Method message_for_email has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
      Open

          def message_for_email(user, post, type, notification, args = nil)
            args ||= {}
      
            notification_type = args[:notification_type]
            notification_data_hash = args[:notification_data_hash]
      Severity: Minor
      Found in app/jobs/regular/user_email.rb - About 5 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

      Class Restorer has 43 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class Restorer
          attr_reader :success
      
          def self.pg_produces_portable_dump?(version)
            version = Gem::Version.new(version)
      Severity: Minor
      Found in lib/backup_restore/restorer.rb - About 5 hrs to fix

        Method download has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.download(url,
                            max_file_size:,
                            tmp_file_name:,
                            follow_redirect: false,
                            read_timeout: 5,
        Severity: Minor
        Found in lib/file_helper.rb - About 5 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 new_user_narrative.rb has 405 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require 'distributed_mutex'
        
        module DiscourseNarrativeBot
          class NewUserNarrative < Base
            I18N_KEY = "discourse_narrative_bot.new_user_narrative".freeze

          Class PostAction has 42 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class PostAction < ActiveRecord::Base
            class AlreadyActed < StandardError; end
            class FailedToCreatePost < StandardError; end
          
            include RateLimiter::OnCreateRecord
          Severity: Minor
          Found in app/models/post_action.rb - About 5 hrs to fix

            Class TopicViewSerializer has 41 methods (exceeds 20 allowed). Consider refactoring.
            Open

            class TopicViewSerializer < ApplicationSerializer
              include PostStreamSerializerMixin
              include SuggestedTopicsMixin
              include TopicTagsMixin
              include ApplicationHelper
            Severity: Minor
            Found in app/serializers/topic_view_serializer.rb - About 5 hrs to fix

              File site_setting_extension.rb has 395 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              require_dependency 'site_settings/deprecated_settings'
              require_dependency 'site_settings/type_supervisor'
              require_dependency 'site_settings/defaults_provider'
              require_dependency 'site_settings/db_provider'
              
              
              Severity: Minor
              Found in lib/site_setting_extension.rb - About 5 hrs to fix

                Method update has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
                Open

                    def self.update(post, polls)
                      ::Poll.transaction do
                        has_changed = false
                        edit_window = SiteSetting.poll_edit_window_mins
                
                
                Severity: Minor
                Found in plugins/poll/lib/polls_updater.rb - About 5 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 ensure_entry_for has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
                Open

                  def self.ensure_entry_for(post, link, parsed)
                    url = link.url
                    internal = false
                    topic_id = nil
                    post_number = nil
                Severity: Minor
                Found in app/models/topic_link.rb - About 5 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 set_or_create_timer has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
                Open

                  def set_or_create_timer(status_type, time, by_user: nil, based_on_last_post: false, category_id: SiteSetting.uncategorized_category_id)
                    return delete_topic_timer(status_type, by_user: by_user) if time.blank?
                
                    public_topic_timer = !!TopicTimer.public_types[status_type]
                    topic_timer_options = { topic: self, public_type: public_topic_timer }
                Severity: Minor
                Found in app/models/topic.rb - About 5 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_allowed_tags has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
                Open

                  def self.filter_allowed_tags(query, guardian, opts = {})
                    selected_tag_ids = opts[:selected_tags] ? Tag.where_name(opts[:selected_tags]).pluck(:id) : []
                
                    if !opts[:for_topic] && !selected_tag_ids.empty?
                      query = query.where('tags.id NOT IN (?)', selected_tag_ids)
                Severity: Minor
                Found in lib/discourse_tagging.rb - About 5 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 post_creator.rb has 389 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                require_dependency 'rate_limiter'
                require_dependency 'topic_creator'
                require_dependency 'post_jobs_enqueuer'
                require_dependency 'distributed_mutex'
                require_dependency 'has_errors'
                Severity: Minor
                Found in lib/post_creator.rb - About 5 hrs to fix

                  Class UsersController has 40 methods (exceeds 20 allowed). Consider refactoring.
                  Open

                  class Admin::UsersController < Admin::AdminController
                  
                    before_action :fetch_user, only: [:suspend,
                                                      :unsuspend,
                                                      :refresh_browsers,
                  Severity: Minor
                  Found in app/controllers/admin/users_controller.rb - About 5 hrs to fix

                    Method show_in_site has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def show_in_site(hostname)
                    
                        username = params[:username].to_s
                        return render_blank unless user = User.find_by(username_lower: username.downcase)
                    
                    
                    Severity: Minor
                    Found in app/controllers/user_avatars_controller.rb - About 5 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 create_notification has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def create_notification(user, type, post, opts = {})
                        opts = @default_opts.merge(opts)
                    
                        DiscourseEvent.trigger(:before_create_notification, user, type, post, opts)
                    
                    
                    Severity: Minor
                    Found in app/services/post_alerter.rb - About 5 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 digest has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def digest(user, opts = {})
                        build_summary_for(user)
                        min_date = opts[:since] || user.last_emailed_at || user.last_seen_at || 1.month.ago
                    
                        # Fetch some topics and posts to show
                    Severity: Minor
                    Found in app/mailers/user_notifications.rb - About 5 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 tag_topic_by_names has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def self.tag_topic_by_names(topic, guardian, tag_names_arg, append: false)
                        if guardian.can_tag?(topic)
                          tag_names = DiscourseTagging.tags_for_saving(tag_names_arg, guardian) || []
                    
                          old_tag_names = topic.tags.pluck(:name) || []
                    Severity: Minor
                    Found in lib/discourse_tagging.rb - About 5 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 build_short_edit_script has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def build_short_edit_script(shortest_path)
                        ses = []
                        x, y = 1, 1
                        px, py = 0, 0
                        i = shortest_path.length - 1
                    Severity: Minor
                    Found in lib/onpdiff.rb - About 5 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

                    Severity
                    Category
                    Status
                    Source
                    Language