discourse/discourse

View on GitHub

Showing 1,474 of 1,778 total issues

Method stylesheet_details has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

  def self.stylesheet_details(target = :desktop, media = 'all', theme_ids = :missing)
    if theme_ids == :missing
      theme_ids = [SiteSetting.default_theme_id]
    end

Severity: Minor
Found in lib/stylesheet/manager.rb - About 4 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 can_invite_to? has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

  def can_invite_to?(object, groups = nil)
    return false unless authenticated?
    is_topic = object.is_a?(Topic)
    return true if is_admin? && !is_topic
    return false if (SiteSetting.max_invites_per_day.to_i == 0 && !is_staff?)
Severity: Minor
Found in lib/guardian.rb - About 4 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 UserNotifications has 36 methods (exceeds 20 allowed). Consider refactoring.
Open

class UserNotifications < ActionMailer::Base
  include UserNotificationsHelper
  include ApplicationHelper
  helper :application, :email
  default charset: 'UTF-8'
Severity: Minor
Found in app/mailers/user_notifications.rb - About 4 hrs to fix

    File guardian.rb has 361 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_dependency 'guardian/category_guardian'
    require_dependency 'guardian/ensure_magic'
    require_dependency 'guardian/post_guardian'
    require_dependency 'guardian/topic_guardian'
    require_dependency 'guardian/user_guardian'
    Severity: Minor
    Found in lib/guardian.rb - About 4 hrs to fix

      Method actions_summary has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

        def actions_summary
          result = []
          can_see_post = scope.can_see_post?(object)
      
          PostActionType.types.except(:bookmark).each do |sym, id|
      Severity: Minor
      Found in app/serializers/post_serializer.rb - About 4 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 distance_of_time_in_words has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {})
            options = {
              scope: :'datetime.distance_in_words',
            }.merge!(options)
      
      
      Severity: Minor
      Found in lib/freedom_patches/rails4.rb - About 4 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 reviewable.rb has 357 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require_dependency 'enum'
      require_dependency 'reviewable/actions'
      require_dependency 'reviewable/conversation'
      require_dependency 'reviewable/editable_fields'
      require_dependency 'reviewable/perform_result'
      Severity: Minor
      Found in app/models/reviewable.rb - About 4 hrs to fix

        Class CurrentUserSerializer has 35 methods (exceeds 20 allowed). Consider refactoring.
        Open

        class CurrentUserSerializer < BasicUserSerializer
        
          attributes :name,
                     :unread_notifications,
                     :unread_private_messages,
        Severity: Minor
        Found in app/serializers/current_user_serializer.rb - About 4 hrs to fix

          File list_controller.rb has 353 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require_dependency 'topic_list_responder'
          
          class ListController < ApplicationController
            include TopicListResponder
          
          
          Severity: Minor
          Found in app/controllers/list_controller.rb - About 4 hrs to fix

            Method toggle_status has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
            Open

                  def toggle_status(post_id, poll_name, status, user, raise_errors = true)
                    Poll.transaction do
                      post = Post.find_by(id: post_id)
            
                      # post must not be deleted
            Severity: Minor
            Found in plugins/poll/plugin.rb - About 4 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 match_email_or_create_user has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
            Open

              def match_email_or_create_user(ip_address)
                # Use a mutex here to counter SSO requests that are sent at the same time w
                # the same email payload
                DistributedMutex.synchronize("discourse_single_sign_on_#{email}") do
                  user = User.find_by_email(email) if !require_activation
            Severity: Minor
            Found in app/models/discourse_single_sign_on.rb - About 4 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 setup_deprecated_methods has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
            Open

              def setup_deprecated_methods
                SETTINGS.each do |old_setting, new_setting, override, version|
                  unless override
                    SiteSetting.singleton_class.public_send(
                      :alias_method, :"_#{old_setting}", :"#{old_setting}"
            Severity: Minor
            Found in lib/site_settings/deprecated_settings.rb - About 4 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 up has 110 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def up
                # Ensure we don't have duplicate polls
                DB.exec <<~SQL
                  WITH duplicates AS (
                    SELECT id, row_number() OVER (PARTITION BY post_id) r
            Severity: Major
            Found in plugins/poll/db/post_migrate/20180820080623_migrate_polls_data.rb - About 4 hrs to fix

              Method flagged_posts_report has 109 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def self.flagged_posts_report(current_user, opts = nil)
                  Discourse.deprecate("FlagQuery is deprecated, use the Reviewable API instead.", since: "2.3.0beta5", drop_from: "2.4")
              
                  opts ||= {}
                  offset = opts[:offset] || 0
              Severity: Major
              Found in lib/flag_query.rb - About 4 hrs to fix

                Method create_notification has 108 lines of code (exceeds 25 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: Major
                Found in app/services/post_alerter.rb - About 4 hrs to fix

                  File post_serializer.rb has 344 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

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

                    File svg_sprite.rb has 344 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    require_dependency 'distributed_cache'
                    
                    module SvgSprite
                      SVG_ICONS ||= Set.new([
                        "adjust",
                    Severity: Minor
                    Found in lib/svg_sprite/svg_sprite.rb - About 4 hrs to fix

                      Method update has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def update
                          @theme = Theme.find(params[:id])
                      
                          original_json = ThemeSerializer.new(@theme, root: false).to_json
                      
                      
                      Severity: Minor
                      Found in app/controllers/admin/themes_controller.rb - About 4 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 show_resource has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def show_resource(source_map: false)
                      
                          extension = source_map ? ".css.map" : ".css"
                      
                          params[:name]
                      Severity: Minor
                      Found in app/controllers/stylesheets_controller.rb - About 4 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 validate_value has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def validate_value(name, type, val)
                          if type == self.class.types[:enum]
                            if enum_class(name)
                              raise Discourse::InvalidParameters.new(:value) unless enum_class(name).valid_value?(val)
                            else
                      Severity: Minor
                      Found in lib/site_settings/type_supervisor.rb - About 4 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