discourse/discourse

View on GitHub

Showing 1,139 of 1,401 total issues

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

class TopicsController < ApplicationController
  before_action :ensure_logged_in, only: [:timings,
                                          :destroy_timings,
                                          :update,
                                          :star,
Severity: Major
Found in app/controllers/topics_controller.rb - About 7 hrs to fix

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

      def create
        params.require(:email)
        params.permit(:user_fields)
    
        unless SiteSetting.allow_new_registrations
    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

    Class Guardian has 52 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 7 hrs to fix

      Class TopicQuery has 51 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class TopicQuery
      
        def self.public_valid_options
          @public_valid_options ||=
            %i(page
      Severity: Major
      Found in lib/topic_query.rb - About 7 hrs to fix

        Method build has 178 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 7 hrs to fix

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

          class UsersController < ApplicationController
          
            skip_before_action :authorize_mini_profiler, only: [:avatar]
            skip_before_action :check_xhr, only: [:show, :badges, :password_reset, :update, :account_created, :activate_account, :perform_account_activation, :user_preferences_redirect, :avatar, :my_redirect, :toggle_anon, :admin_login, :confirm_admin]
          
          
          Severity: Minor
          Found in app/controllers/users_controller.rb - About 7 hrs to fix

            File post_action.rb has 458 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            require_dependency 'rate_limiter'
            require_dependency 'system_message'
            
            class PostAction < ActiveRecord::Base
              class AlreadyActed < StandardError; end
            Severity: Minor
            Found in app/models/post_action.rb - About 7 hrs to fix

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

              require_dependency 'markdown_linker'
              require_dependency 'email/message_builder'
              require_dependency 'age_words'
              require_dependency 'rtl'
              
              
              Severity: Minor
              Found in app/mailers/user_notifications.rb - About 6 hrs to fix

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

                  def sso_login
                    raise Discourse::NotFound.new unless SiteSetting.enable_sso
                
                    sso = DiscourseSingleSignOn.parse(request.query_string)
                    if !sso.nonce_valid?
                Severity: Minor
                Found in app/controllers/session_controller.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 send_notification_email has a Cognitive Complexity of 44 (exceeds 5 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: Minor
                Found in app/mailers/user_notifications.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 44 (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 = URI.parse(url) rescue nil
                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

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

                  def password_reset
                    expires_now
                
                    token = params[:token]
                
                
                Severity: Minor
                Found in app/controllers/users_controller.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 42 (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

                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

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

                class Category < ActiveRecord::Base
                  include Searchable
                  include Positionable
                  include HasCustomFields
                  include CategoryHashtag
                Severity: Minor
                Found in app/models/category.rb - About 6 hrs to fix

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

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

                  class PostsController < ApplicationController
                  
                    before_action :ensure_logged_in, except: [:show, :replies, :by_number, :short_link, :reply_history, :replyIids, :revisions, :latest_revision, :expand_embed, :markdown_id, :markdown_num, :cooked, :latest, :user_posts_feed]
                  
                    skip_before_action :preload_json, :check_xhr, only: [:markdown_id, :markdown_num, :short_link, :latest, :user_posts_feed]
                  Severity: Minor
                  Found in app/controllers/posts_controller.rb - About 6 hrs to fix

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

                    require 'digest/sha1'
                    require 'fileutils'
                    require_dependency 'plugin/metadata'
                    require_dependency 'plugin/auth_provider'
                    
                    
                    Severity: Minor
                    Found in lib/plugin/instance.rb - About 6 hrs to fix

                      File post_alerter.rb has 415 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 5 hrs to fix
                        Severity
                        Category
                        Status
                        Source