discourse/discourse

View on GitHub

Showing 1,669 of 1,992 total issues

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

  def sso_login
    raise Discourse::NotFound.new unless SiteSetting.enable_sso

    params.require(:sso)
    params.require(:sig)
Severity: Minor
Found in app/controllers/session_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 groups_controller.rb has 486 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 7 hrs to fix

    Method show has a Cognitive Complexity of 49 (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 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 474 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 7 hrs to fix

      File reviewable.rb has 473 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      class Reviewable < ActiveRecord::Base
        class UpdateConflict < StandardError; end
      
        class InvalidAction < StandardError
          def initialize(action_id, klass)
      Severity: Minor
      Found in app/models/reviewable.rb - About 7 hrs to fix

        File session_controller.rb has 473 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        class SessionController < ApplicationController
          class LocalLoginNotAllowed < StandardError; end
          rescue_from LocalLoginNotAllowed do
            render body: nil, status: 500
          end
        Severity: Minor
        Found in app/controllers/session_controller.rb - About 7 hrs to fix

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

            class Restorer
              attr_reader :success
          
              def self.pg_produces_portable_dump?(version)
                # anything pg 11 or above will produce a non-portable dump
          Severity: Major
          Found in lib/backup_restore/restorer.rb - About 7 hrs to fix

            Method message_for_email has a Cognitive Complexity of 47 (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 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 PostRevisor has 50 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 7 hrs to fix

              File post_mover.rb has 457 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              class PostMover
                attr_reader :original_topic, :destination_topic, :user, :post_ids
              
                def self.move_types
                  @move_types ||= Enum.new(:new_topic, :existing_topic)
              Severity: Minor
              Found in app/models/post_mover.rb - About 7 hrs to fix

                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 Group has 49 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class Group < ActiveRecord::Base
                  include HasCustomFields
                  include AnonCacheInvalidator
                  include HasDestroyedWebHook
                
                
                Severity: Minor
                Found in app/models/group.rb - About 6 hrs to fix

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

                      def update(attributes = {})
                        user_profile = user.user_profile
                        user_profile.location = attributes.fetch(:location) { user_profile.location }
                        user_profile.dismissed_banner_key = attributes[:dismissed_banner_key] if attributes[:dismissed_banner_key].present?
                        user_profile.website = format_url(attributes.fetch(:website) { user_profile.website })
                    Severity: Minor
                    Found in app/services/user_updater.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 44 (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 start_element has a Cognitive Complexity of 44 (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

                    Class PostsController has 48 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 48 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

                        Function from has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
                        Open

                          Array.from = (function() {
                            var toStr = Object.prototype.toString;
                            var isCallable = function(fn) {
                              return typeof fn === "function" || toStr.call(fn) === "[object Function]";
                            };
                        Severity: Minor
                        Found in app/assets/javascripts/polyfills.js - 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 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

                        Severity
                        Category
                        Status
                        Source
                        Language