discourse/discourse

View on GitHub

Showing 1,669 of 1,992 total issues

Class StaffActionLogger has 67 methods (exceeds 20 allowed). Consider refactoring.
Open

class StaffActionLogger

  def self.base_attrs
    [:topic_id, :post_id, :context, :subject, :ip_address, :previous_value, :new_value]
  end
Severity: Major
Found in app/services/staff_action_logger.rb - About 1 day to fix

    File user_notifications.rb has 572 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

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

      File instance.rb has 572 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'digest/sha1'
      require 'fileutils'
      require_dependency 'plugin/metadata'
      require_dependency 'auth'
      
      
      Severity: Major
      Found in lib/plugin/instance.rb - About 1 day to fix

        Class Guardian has 66 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class Guardian
          include EnsureMagic
          include CategoryGuardian
          include PostGuardian
          include TopicGuardian
        Severity: Major
        Found in lib/guardian.rb - About 1 day to fix

          Method send has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
          Open

              def send
                bypass_disable = BYPASS_DISABLE_TYPES.include?(@email_type.to_s)
          
                if SiteSetting.disable_emails == "yes" && !bypass_disable
                  return
          Severity: Minor
          Found in lib/email/sender.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

          Method build has 239 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def build
                return @wizard unless SiteSetting.wizard_enabled? && @wizard.user.try(:staff?)
          
                @wizard.append_step('locale') do |step|
                  step.banner = "welcome.png"
          Severity: Major
          Found in lib/wizard/builder.rb - About 1 day to fix

            Method resolve has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
            Open

              def resolve
                if @uri && @uri.port == 80 && FinalDestination.is_https_domain?(@uri.hostname)
                  @uri.scheme = "https"
                  @uri = URI(@uri.to_s)
                end
            Severity: Minor
            Found in lib/final_destination.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

            Method tag_topic_by_names has a Cognitive Complexity of 58 (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 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

            File cooked_post_processor.rb has 542 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            class CookedPostProcessor
              INLINE_ONEBOX_LOADING_CSS_CLASS = "inline-onebox-loading"
              INLINE_ONEBOX_CSS_CLASS = "inline-onebox"
              LIGHTBOX_WRAPPER_CSS_CLASS = "lightbox-wrapper"
              LOADING_SIZE = 10
            Severity: Major
            Found in lib/cooked_post_processor.rb - About 1 day to fix

              File post_alerter.rb has 539 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              class PostAlerter
                def self.post_created(post, opts = {})
                  PostAlerter.new(opts).after_save_post(post, true)
                  post
                end
              Severity: Major
              Found in app/services/post_alerter.rb - About 1 day to fix

                Class TopicsController has 61 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class TopicsController < ApplicationController
                  requires_login only: [
                    :timings,
                    :destroy_timings,
                    :update,
                Severity: Major
                Found in app/controllers/topics_controller.rb - About 1 day to fix

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

                  require_dependency "db_helper"
                  
                  module BackupRestore
                  
                    class RestoreDisabledError < RuntimeError; end
                  Severity: Major
                  Found in lib/backup_restore/restorer.rb - About 1 day to fix

                    Class ApplicationController has 60 methods (exceeds 20 allowed). Consider refactoring.
                    Open

                    class ApplicationController < ActionController::Base
                      include CurrentUser
                      include CanonicalURL::ControllerExtensions
                      include JsonError
                      include GlobalPath
                    Severity: Major
                    Found in app/controllers/application_controller.rb - About 1 day to fix

                      Method up has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def up
                          # Ensure we don't have duplicate polls
                          DB.exec <<~SQL
                            WITH duplicates AS (
                              SELECT id, row_number() OVER (PARTITION BY post_id) r
                      Severity: Minor
                      Found in plugins/poll/db/post_migrate/20180820080623_migrate_polls_data.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 59 methods (exceeds 20 allowed). Consider refactoring.
                      Open

                      class TopicQuery
                        PG_MAX_INT ||= 2147483647
                      
                        def self.validators
                          @validators ||= begin
                      Severity: Major
                      Found in lib/topic_query.rb - About 1 day to fix

                        File advanced_user_narrative_spec.rb has 516 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        require 'rails_helper'
                        
                        RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
                          let(:discobot_user) { User.find(-2) }
                          let(:first_post) { Fabricate(:post, user: discobot_user) }

                          Method backfill has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def self.backfill(badge, opts = nil)
                              return unless SiteSetting.enable_badges
                              return unless badge.enabled
                              return unless badge.query.present?
                          
                          
                          Severity: Minor
                          Found in app/services/badge_granter.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

                          Method create has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def create
                              params.require(:email)
                              params.require(:username)
                              params.permit(:user_fields)
                          
                          
                          Severity: Minor
                          Found in app/controllers/users_controller.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

                          Method hijack has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def hijack(&blk)
                              controller_class = self.class
                          
                              if hijack = request.env['rack.hijack']
                          
                          
                          Severity: Minor
                          Found in lib/hijack.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

                          Method migrate_to_new_scheme has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
                          Open

                            def self.migrate_to_new_scheme(limit: nil)
                              problems = []
                          
                              DistributedMutex.synchronize("migrate_upload_to_new_scheme") do
                                if SiteSetting.migrate_to_new_scheme
                          Severity: Minor
                          Found in app/models/upload.rb - About 7 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