discourse/discourse

View on GitHub

Showing 1,669 of 1,992 total issues

Method posts_query has 127 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def posts_query(limit, opts = nil)
    opts ||= {}

    posts = Post.where(post_type: Topic.visible_post_types(@guardian.user))
      .joins(:post_search_data, :topic)
Severity: Major
Found in lib/search.rb - About 5 hrs to fix

    File pretty_text.rb has 377 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'mini_racer'
    require 'nokogiri'
    require 'erb'
    
    module PrettyText
    Severity: Minor
    Found in lib/pretty_text.rb - About 5 hrs to fix

      Method change_external_attributes_and_override has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

        def change_external_attributes_and_override(sso_record, user)
          if SiteSetting.sso_overrides_email && user.email != Email.downcase(email)
            user.email = email
            user.active = false if require_activation
          end
      Severity: Minor
      Found in app/models/discourse_single_sign_on.rb - About 4 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 index has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.index(obj, force: false)
          return if @disabled
      
          category_name = nil
          tag_names = nil
      Severity: Minor
      Found in app/services/search_indexer.rb - About 4 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 select_body has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          def select_body
            text = nil
            html = nil
            text_content_type = nil
      
      
      Severity: Minor
      Found in lib/email/receiver.rb - About 4 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 TrustLevel3Requirements has 37 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class TrustLevel3Requirements
      
        class PenaltyCounts
          attr_reader :silenced, :suspended
      
      
      Severity: Minor
      Found in app/models/trust_level3_requirements.rb - About 4 hrs to fix

        Class UserNotifications has 37 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class UserNotifications < ActionMailer::Base
          include UserNotificationsHelper
          include ApplicationHelper
          helper :application, :email
          default charset: 'UTF-8'
        Severity: Minor
        Found in app/mailers/user_notifications.rb - About 4 hrs to fix

          Class PostCreator has 37 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class PostCreator
            include HasErrors
          
            attr_reader :opts
          
          
          Severity: Minor
          Found in lib/post_creator.rb - About 4 hrs to fix

            Method input has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
            Open

                def input(input, user, post: nil, topic_id: nil, skip: false)
                  new_post = nil
                  @post = post
                  @topic_id = topic_id
                  @skip = skip
            Severity: Minor
            Found in plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.rb - About 4 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 index has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
            Open

              def index
                raise Discourse::InvalidAccess.new(:enable_user_directory) unless SiteSetting.enable_user_directory?
            
                period = params.require(:period)
                period_type = DirectoryItem.period_types[period.to_sym]
            Severity: Minor
            Found in app/controllers/directory_items_controller.rb - About 4 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 32 (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 4 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 start has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
            Open

                def start
            
                  Thread.new do
                    begin
                      while true
            Severity: Minor
            Found in lib/stylesheet/watcher.rb - About 4 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 stylesheet_details has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.stylesheet_details(target = :desktop, media = 'all', theme_ids = :missing)
                if theme_ids == :missing
                  theme_ids = [SiteSetting.default_theme_id]
                end
            
            
            Severity: Minor
            Found in lib/stylesheet/manager.rb - About 4 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 can_invite_to? has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
            Open

              def can_invite_to?(object, groups = nil)
                return false unless authenticated?
                is_topic = object.is_a?(Topic)
                return true if is_admin? && !is_topic
                return false if (SiteSetting.max_invites_per_day.to_i == 0 && !is_staff?)
            Severity: Minor
            Found in lib/guardian.rb - About 4 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 html_for has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.html_for(category, opts = nil)
                opts = opts || {}
            
                # If there is no category, bail
                return "" if category.blank?
            Severity: Minor
            Found in lib/category_badge.rb - About 4 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 backuper.rb has 363 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            require "mini_mime"
            require "file_store/s3_store"
            
            module BackupRestore
            
            
            Severity: Minor
            Found in lib/backup_restore/backuper.rb - About 4 hrs to fix

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

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

                Class CurrentUserSerializer has 36 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class CurrentUserSerializer < BasicUserSerializer
                
                  attributes :name,
                             :unread_notifications,
                             :unread_private_messages,
                Severity: Minor
                Found in app/serializers/current_user_serializer.rb - About 4 hrs to fix

                  File svg_sprite.rb has 361 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  module SvgSprite
                    SVG_ICONS ||= Set.new([
                      "adjust",
                      "ambulance",
                      "anchor",
                  Severity: Minor
                  Found in lib/svg_sprite/svg_sprite.rb - About 4 hrs to fix

                    Method distance_of_time_in_words has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def self.distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {})
                          options = {
                            scope: :'datetime.distance_in_words',
                          }.merge!(options)
                    
                    
                    Severity: Minor
                    Found in lib/freedom_patches/rails4.rb - About 4 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