discourse/discourse

View on GitHub

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

  def create_for(user_id)
    if filesize <= 0
      @upload.errors.add(:base, I18n.t("upload.empty"))
      return @upload
    end
Severity: Minor
Found in lib/upload_creator.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 post.rb has 550 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_dependency 'pretty_text'
require_dependency 'rate_limiter'
require_dependency 'post_revisor'
require_dependency 'enum'
require_dependency 'post_analyzer'
Severity: Major
Found in app/models/post.rb - About 1 day to fix

    Method show has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
    Open

      def show
        if request.referer
          flash["referer"] ||= request.referer[0..255]
        end
    
    
    Severity: Minor
    Found in app/controllers/topics_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 backfill has a Cognitive Complexity of 55 (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 execute has a Cognitive Complexity of 54 (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 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 group.rb has 516 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_dependency 'enum'
    
    class Group < ActiveRecord::Base
      include HasCustomFields
      include AnonCacheInvalidator
    Severity: Major
    Found in app/models/group.rb - About 1 day to fix

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

          def send
            return if SiteSetting.disable_emails && @email_type.to_s != "admin_login"
      
            return if ActionMailer::Base::NullMail === @message
            return if ActionMailer::Base::NullMail === (@message.message rescue nil)
      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

      Class ApplicationController has 57 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

        Class PostSerializer has 57 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class PostSerializer < BasicPostSerializer
        
          # To pass in additional information we might need
          INSTANCE_VARS ||= [
            :topic_view,
        Severity: Major
        Found in app/serializers/post_serializer.rb - About 1 day to fix

          Class TopicView has 57 methods (exceeds 20 allowed). Consider refactoring.
          Open

          class TopicView
          
            attr_reader :topic, :posts, :guardian, :filtered_posts, :chunk_size, :print, :message_bus_last_id
            attr_accessor :draft, :draft_key, :draft_sequence, :user_custom_fields, :post_custom_fields
          
          
          Severity: Major
          Found in lib/topic_view.rb - About 1 day to fix

            Method resolve has a Cognitive Complexity of 52 (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 vote has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
            Open

                  def vote(post_id, poll_name, options, user)
                    DistributedMutex.synchronize("#{PLUGIN_NAME}-#{post_id}") do
                      user_id = user.id
                      post = Post.find_by(id: post_id)
            
            
            Severity: Minor
            Found in plugins/poll/plugin.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 posts_controller.rb has 501 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            require_dependency 'new_post_manager'
            require_dependency 'post_creator'
            require_dependency 'post_destroyer'
            require_dependency 'post_merger'
            require_dependency 'distributed_memoizer'
            Severity: Major
            Found in app/controllers/posts_controller.rb - About 1 day to fix

              File advanced_user_narrative_spec.rb has 497 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 publish has a Cognitive Complexity of 51 (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 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 Instance has 55 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class Plugin::Instance
                
                  attr_accessor :path, :metadata
                  attr_reader :admin_route
                
                
                Severity: Major
                Found in lib/plugin/instance.rb - About 7 hrs to fix

                  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

                  Class Receiver has 54 methods (exceeds 20 allowed). Consider refactoring.
                  Open

                    class Receiver
                      include ActionView::Helpers::NumberHelper
                  
                      # If you add a new error, you need to
                      #   * add it to Email::Processor#handle_failure()
                  Severity: Major
                  Found in lib/email/receiver.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 application_controller.rb has 482 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    require 'current_user'
                    require_dependency 'canonical_url'
                    require_dependency 'discourse'
                    require_dependency 'custom_renderer'
                    require_dependency 'archetype'
                    Severity: Minor
                    Found in app/controllers/application_controller.rb - About 7 hrs to fix
                      Severity
                      Category
                      Status