discourse/discourse

View on GitHub

Showing 1,538 of 1,538 total issues

Method voters has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

    def voters
      post_id = params.require(:post_id)
      poll_name = params.require(:poll_name)

      post = Post.find_by(id: post_id)
Severity: Minor
Found in plugins/poll/plugin.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 execute has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

    def execute(args)
      return unless SiteSetting.download_remote_images_to_local?

      post_id = args[:post_id]
      raise Discourse::InvalidParameters.new(:post_id) unless post_id.present?
Severity: Minor
Found in app/jobs/regular/pull_hotlinked_images.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 TopicQuery has 54 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

    Class TopicsController has 54 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 7 hrs to fix

      Class StaffActionLogger has 54 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 7 hrs to fix

        Method build has a Cognitive Complexity of 49 (exceeds 5 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: Minor
        Found in lib/wizard/builder.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

        File staff_action_logger.rb has 480 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require_dependency 'staff_message_format'
        
        # Responsible for logging the actions of admins and moderators.
        class StaffActionLogger
        
        
        Severity: Minor
        Found in app/services/staff_action_logger.rb - About 7 hrs to fix

          File post_action.rb has 479 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

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

            class UsersController < ApplicationController
            
              skip_before_action :authorize_mini_profiler, only: [:avatar]
            
              requires_login only: [
            Severity: Major
            Found in app/controllers/users_controller.rb - About 7 hrs to fix

              File instance.rb has 472 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 7 hrs to fix

                File users_controller.rb has 469 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 create has a Cognitive Complexity of 47 (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

                  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

                    Method create_from has a Cognitive Complexity of 46 (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 = begin
                    Severity: Minor
                    Found in app/models/topic_link_click.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 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

                    File post_revisor.rb has 455 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 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 password_reset has a Cognitive Complexity of 45 (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

                      File post_alerter.rb has 453 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

                        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
                          Severity
                          Category
                          Status
                          Source
                          Language