discourse/discourse

View on GitHub

Showing 1,237 of 1,498 total issues

File users_controller.rb has 430 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_dependency 'user_destroyer'
require_dependency 'admin_user_index_query'
require_dependency 'admin_confirmation'

class Admin::UsersController < Admin::AdminController
Severity: Minor
Found in app/controllers/admin/users_controller.rb - About 6 hrs to fix

    Method html_for has a Cognitive Complexity of 41 (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 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

    Method publish has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

        def publish
          data = params.permit(
            :response_needed,
            current: [:action, :topic_id, :post_id],
            previous: [:action, :topic_id, :post_id]
    Severity: Minor
    Found in plugins/discourse-presence/plugin.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 45 methods (exceeds 20 allowed). Consider refactoring.
    Open

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

      Class PostsController has 45 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class PostsController < ApplicationController
      
        requires_login except: [
          :show,
          :replies,
      Severity: Minor
      Found in app/controllers/posts_controller.rb - About 6 hrs to fix

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

        require_dependency 'distributed_mutex'
        require_dependency 'user_action_creator'
        
        class PostAlerter
          def self.post_created(post, opts = {})
        Severity: Minor
        Found in app/services/post_alerter.rb - About 6 hrs to fix

          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

          Method message_for_email has a Cognitive Complexity of 40 (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 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

          Method default_results has 149 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 5 hrs to fix

            File restorer.rb has 408 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 5 hrs to fix

              Method send_notification_email has 144 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def send_notification_email(opts)
                  post = opts[:post]
                  title = opts[:title]
              
                  allow_reply_by_email = opts[:allow_reply_by_email]
              Severity: Major
              Found in app/mailers/user_notifications.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

                File topic_view.rb has 406 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                require_dependency 'guardian'
                require_dependency 'topic_query'
                require_dependency 'filter_best_posts'
                require_dependency 'gaps'
                
                
                Severity: Minor
                Found in lib/topic_view.rb - About 5 hrs to fix

                  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

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

                    require_dependency 'url_helper'
                    require_dependency 'pretty_text'
                    require_dependency 'quote_comparer'
                    
                    class CookedPostProcessor
                    Severity: Minor
                    Found in lib/cooked_post_processor.rb - About 5 hrs to fix

                      File new_user_narrative.rb has 403 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 DiscoursePluginRegistry has 42 methods (exceeds 20 allowed). Consider refactoring.
                          Open

                          class DiscoursePluginRegistry
                          
                            class << self
                              attr_writer :javascripts
                              attr_writer :service_workers
                          Severity: Minor
                          Found in lib/discourse_plugin_registry.rb - About 5 hrs to fix

                            File groups_controller.rb has 400 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 5 hrs to fix

                              File category.rb has 398 lines of code (exceeds 250 allowed). Consider refactoring.
                              Open

                              require_dependency 'distributed_cache'
                              
                              class Category < ActiveRecord::Base
                                include Searchable
                                include Positionable
                              Severity: Minor
                              Found in app/models/category.rb - About 5 hrs to fix
                                Severity
                                Category
                                Status
                                Source
                                Language