discourse/discourse

View on GitHub

Showing 1,447 of 1,747 total issues

Method start_element has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

  def start_element(name, attributes = [])
    case name
    when "img"
      attributes = Hash[*attributes.flatten]

Severity: Minor
Found in lib/excerpt_parser.rb - About 6 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 Group has 44 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 6 hrs to fix

    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

      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 PostAction has 43 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

        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

          File 006_badges.rb has 404 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 5 hrs to fix

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

            class Theme < ActiveRecord::Base
            
              @cache = DistributedCache.new('theme')
            
              belongs_to :user
            Severity: Minor
            Found in app/models/theme.rb - About 5 hrs to fix

              Method update has a Cognitive Complexity of 37 (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

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

              class PostAlerter
                def self.post_created(post, opts = {})
                  PostAlerter.new(opts).after_save_post(post, true)
                  post
                end
              Severity: Minor
              Found in app/services/post_alerter.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 394 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 application_helper.rb has 390 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    require 'current_user'
                    require 'canonical_url'
                    require_dependency 'guardian'
                    require_dependency 'unread'
                    require_dependency 'age_words'
                    Severity: Minor
                    Found in app/helpers/application_helper.rb - About 5 hrs to fix

                      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

                        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

                        Severity
                        Category
                        Status
                        Source
                        Language