discourse/discourse

View on GitHub

Showing 1,291 of 1,560 total issues

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

    Method current_user has a Cognitive Complexity of 45 (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

    File post_alerter.rb has 454 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 send_notification_email has 171 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

        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 post_process_oneboxes has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
          Open

            def post_process_oneboxes
              Oneboxer.apply(@doc) do |url|
                @has_oneboxes = true
                Oneboxer.onebox(url,
                  invalidate_oneboxes: !!@opts[:invalidate_oneboxes],
          Severity: Minor
          Found in lib/cooked_post_processor.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

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

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

            require 'cache'
            require 'open3'
            require_dependency 'route_format'
            require_dependency 'plugin/instance'
            require_dependency 'auth/default_current_user_provider'
            Severity: Minor
            Found in lib/discourse.rb - About 6 hrs to fix

              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

              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 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 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 cooked_post_processor.rb has 414 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

                  Class Group has 43 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 5 hrs to fix

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

                        Severity
                        Category
                        Status
                        Source
                        Language