discourse/discourse

View on GitHub

Showing 1,430 of 1,732 total issues

File users_controller.rb has 467 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 7 hrs to fix

    Method admin_login has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
    Open

      def admin_login
        return redirect_to(path("/")) if current_user
    
        if request.put? && params[:email].present?
          RateLimiter.new(nil, "admin-login-hr-#{request.remote_ip}", 6, 1.hour).performed!
    Severity: Minor
    Found in app/controllers/users_controller.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

    Method report_moderators_activity has 177 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.report_moderators_activity(report)
        report.labels = [
          {
            type: :user,
            properties: {
    Severity: Major
    Found in app/models/report.rb - About 7 hrs to fix

      File post_revisor.rb has 456 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require "edit_rate_limiter"
      require 'post_locker'
      
      class PostRevisor
      
      
      Severity: Minor
      Found in lib/post_revisor.rb - About 6 hrs to fix

        Method send_notification_email has 173 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 6 hrs to fix

          Method save_custom_fields has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
          Open

            def save_custom_fields(force = false)
              if force || !custom_fields_clean?
                dup = @custom_fields.dup
                array_fields = {}
          
          
          Severity: Minor
          Found in app/models/concerns/has_custom_fields.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 create_from has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.create_from(args = {})
              url = args[:url][0...TopicLink.max_url_length]
              return nil if url.blank?
          
              uri = UrlHelper.relaxed_parse(url)
          Severity: Minor
          Found in app/models/topic_link_click.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 PostRevisor has 49 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class PostRevisor
          
            # Helps us track changes to a topic.
            #
            # It's passed to `track_topic_fields` callbacks so they can record if they
          Severity: Minor
          Found in lib/post_revisor.rb - About 6 hrs to fix

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

                def publish
                  raise Discourse::NotFound if current_user.blank? || current_user.user_option.hide_profile_and_presence?
            
                  data = params.permit(
                    :response_needed,
            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

            Method current_user has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
            Open

              def current_user
                return @env[CURRENT_USER_KEY] if @env.key?(CURRENT_USER_KEY)
            
                # bypass if we have the shared session header
                if shared_key = @env['HTTP_X_SHARED_SESSION_KEY']
            Severity: Minor
            Found in lib/auth/default_current_user_provider.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 PostsController has 47 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

              Class DiscoursePluginRegistry has 47 methods (exceeds 20 allowed). Consider refactoring.
              Open

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

                Method recover has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
                Open

                  def recover(posts = Post)
                    posts.where("raw LIKE '%upload:\/\/%' OR raw LIKE '%href=%'").find_each do |post|
                      begin
                        analyzer = PostAnalyzer.new(post.raw, post.topic_id)
                
                
                Severity: Minor
                Found in lib/upload_recovery.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 report_flags_status has 158 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 6 hrs to fix

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

                    def self.create_for(upload, width, height, opts = {})
                  
                      return unless width > 0 && height > 0
                      return if upload.try(:sha1).blank?
                  
                  
                  Severity: Minor
                  Found in app/models/optimized_image.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 create_notification has a Cognitive Complexity of 41 (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 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

                  File groups_controller.rb has 424 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

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

                    class CookedPostProcessor
                      include ActionView::Helpers::NumberHelper
                    
                      INLINE_ONEBOX_LOADING_CSS_CLASS = "inline-onebox-loading"
                      INLINE_ONEBOX_CSS_CLASS = "inline-onebox"
                    Severity: Minor
                    Found in lib/cooked_post_processor.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

                      File restorer.rb has 418 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
                        Severity
                        Category
                        Status
                        Source
                        Language