discourse/discourse

View on GitHub

Showing 1,430 of 1,732 total issues

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

    def input(input, user, post: nil, topic_id: nil, skip: false)
      new_post = nil
      @post = post
      @topic_id = topic_id
      @skip = skip
Severity: Minor
Found in plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.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 index has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

  def index
    raise Discourse::InvalidAccess.new(:enable_user_directory) unless SiteSetting.enable_user_directory?

    period = params.require(:period)
    period_type = DirectoryItem.period_types[period.to_sym]
Severity: Minor
Found in app/controllers/directory_items_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 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

File user_action.rb has 363 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class UserAction < ActiveRecord::Base

  belongs_to :user
  belongs_to :target_post, class_name: "Post"
  belongs_to :target_topic, class_name: "Topic"
Severity: Minor
Found in app/models/user_action.rb - About 4 hrs to fix

    Class PostCreator has 36 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class PostCreator
      include HasErrors
    
      attr_reader :opts
    
    
    Severity: Minor
    Found in lib/post_creator.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

      Class UserNotifications has 35 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 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 process_internal has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
          Open

              def process_internal
                handle_bounce if is_bounce?
                raise NoSenderDetectedError if @from_email.blank?
                raise FromReplyByAddressError if is_from_reply_by_email_address?
                raise ScreenedEmailError if ScreenedEmail.should_block?(@from_email)
          Severity: Minor
          Found in lib/email/receiver.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 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 flagged_posts_report has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.flagged_posts_report(current_user, opts = nil)
                opts ||= {}
                offset = opts[:offset] || 0
                per_page = opts[:per_page] || 25
            
            
            Severity: Minor
            Found in lib/flag_query.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 update_post has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
            Open

              def update_post
                if @fields.has_key?("user_id") && @fields["user_id"] != @post.user_id && @post.user_id != nil
                  prev_owner = User.find(@post.user_id)
                  new_owner = User.find(@fields["user_id"])
            
            
            Severity: Minor
            Found in lib/post_revisor.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

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

              def self.lookup(url, opts = nil)
                opts ||= {}
                opts = opts.with_indifferent_access
            
                unless opts[:skip_cache] || opts[:invalidate]
            Severity: Minor
            Found in lib/inline_oneboxer.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