discourse/discourse

View on GitHub

Showing 1,352 of 1,632 total issues

File groups_controller.rb has 417 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class GroupsController < ApplicationController
  requires_login only: [
    :set_notifications,
    :mentionable,
    :messageable,
Severity: Minor
Found in app/controllers/groups_controller.rb - About 6 hrs to fix

    File restorer.rb has 417 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_dependency "db_helper"
    
    module BackupRestore
    
      class RestoreDisabledError < RuntimeError; end
    Severity: Minor
    Found in lib/backup_restore/restorer.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

        Method report_flags_status has 146 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.report_flags_status(report)
            report.modes = [:table]
        
            report.labels = [
              {
        Severity: Major
        Found in app/models/report.rb - About 5 hrs to fix

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

          class Group < ActiveRecord::Base
            include HasCustomFields
            include AnonCacheInvalidator
            include HasDestroyedWebHook
          
          
          Severity: Minor
          Found in app/models/group.rb - About 5 hrs to fix

            Method create_notification has a Cognitive Complexity of 38 (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 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 Restorer has 42 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

                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

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

                  class CookedPostProcessor
                    include ActionView::Helpers::NumberHelper
                  
                    attr_reader :cooking_options, :doc
                  
                  
                  Severity: Minor
                  Found in lib/cooked_post_processor.rb - About 5 hrs to fix

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

                      def update(attributes = {})
                        user_profile = user.user_profile
                        user_profile.location = attributes.fetch(:location) { user_profile.location }
                        user_profile.dismissed_banner_key = attributes[:dismissed_banner_key] if attributes[:dismissed_banner_key].present?
                        user_profile.website = format_url(attributes.fetch(:website) { user_profile.website })
                    Severity: Minor
                    Found in app/services/user_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 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 391 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 PostAction has 40 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 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 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

                          Severity
                          Category
                          Status
                          Source
                          Language