discourse/discourse

View on GitHub

Showing 1,565 of 1,870 total issues

Method initialize has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(to, opts = nil)
      @to = to
      @opts = opts || {}

      @template_args = {
Severity: Minor
Found in lib/email/message_builder.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 select_body has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

    def select_body
      text = nil
      html = nil
      text_content_type = nil

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

Class TrustLevel3Requirements has 37 methods (exceeds 20 allowed). Consider refactoring.
Open

class TrustLevel3Requirements

  class PenaltyCounts
    attr_reader :silenced, :suspended

Severity: Minor
Found in app/models/trust_level3_requirements.rb - About 4 hrs to fix

    Class PostCreator has 37 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 process has 119 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.process(markdown, on_missing: nil)
          markdown = markdown.dup
      
          match_md_reference(markdown) do |match, src, replacement, index|
            if upload = Upload.get_from_url(src)
      Severity: Major
      Found in app/services/inline_uploads.rb - About 4 hrs to fix

        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

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

          Class CurrentUserSerializer has 36 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 360 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 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

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

                def each_upload_url(fragments: nil, include_local_upload: true)
                  current_db = RailsMultisite::ConnectionManagement.current_db
                  upload_patterns = [
                    /\/uploads\/#{current_db}\//,
                    /\/original\//,
              Severity: Minor
              Found in app/models/post.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 digest has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
              Open

                def digest(user, opts = {})
                  build_summary_for(user)
                  min_date = opts[:since] || user.last_emailed_at || user.last_seen_at || 1.month.ago
              
                  # Fetch some topics and posts to show
              Severity: Minor
              Found in app/mailers/user_notifications.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
                Severity
                Category
                Status
                Source
                Language