discourse/discourse

View on GitHub

Showing 1,150 of 1,413 total issues

Method post_process_oneboxes has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

  def post_process_oneboxes
    args = {
      post_id: @post.id,
      invalidate_oneboxes: !!@opts[:invalidate_oneboxes],
    }
Severity: Minor
Found in lib/cooked_post_processor.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

Class StaffActionLogger has 43 methods (exceeds 20 allowed). Consider refactoring.
Open

class StaffActionLogger

  def self.base_attrs
    [:topic_id, :post_id, :context, :subject, :ip_address, :previous_value, :new_value]
  end
Severity: Minor
Found in app/services/staff_action_logger.rb - About 5 hrs to fix

    Method migrate_to_new_scheme has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.migrate_to_new_scheme(limit = nil)
        problems = []
    
        if SiteSetting.migrate_to_new_scheme
          max_file_size_kb = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes
    Severity: Minor
    Found in app/models/upload.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

    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

    File topic_view.rb has 404 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_dependency 'guardian'
    require_dependency 'topic_query'
    require_dependency 'filter_best_posts'
    require_dependency 'gaps'
    
    
    Severity: Minor
    Found in lib/topic_view.rb - About 5 hrs to fix

      File 006_badges.rb has 404 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'badge_queries'
      
      BadgeGrouping.seed do |g|
        g.id = BadgeGrouping::GettingStarted
        g.name = "Getting Started"
      Severity: Minor
      Found in db/fixtures/006_badges.rb - About 5 hrs to fix

        Method index has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.index(obj, force: false)
            return if @disabled
        
            if obj.class == Post && (obj.saved_change_to_cooked? || force)
              if obj.topic
        Severity: Minor
        Found in app/services/search_indexer.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

        File new_user_narrative.rb has 399 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require 'distributed_mutex'
        
        module DiscourseNarrativeBot
          class NewUserNarrative < Base
            I18N_KEY = "discourse_narrative_bot.new_user_narrative".freeze

          Method default_results has 138 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

            Class PostRevisor has 41 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 5 hrs to fix

              Method start_element has a Cognitive Complexity of 36 (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 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

              Method create_for has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.create_for(upload, width, height, opts = {})
                  return unless width > 0 && height > 0
                  return if upload.try(:sha1).blank?
              
                  DistributedMutex.synchronize("optimized_image_#{upload.id}_#{width}_#{height}") do
              Severity: Minor
              Found in app/models/optimized_image.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

              Method save_custom_fields has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
              Open

                def save_custom_fields(force = false)
                  if force || !custom_fields_clean?
                    dup = @custom_fields.dup
              
                    array_fields = {}
              Severity: Minor
              Found in app/models/concerns/has_custom_fields.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

              Class PostAction has 40 methods (exceeds 20 allowed). Consider refactoring.
              Open

              class PostAction < ActiveRecord::Base
                class AlreadyActed < StandardError; end
              
                include RateLimiter::OnCreateRecord
                include Trashable
              Severity: Minor
              Found in app/models/post_action.rb - About 5 hrs to fix

                File discourse.rb has 388 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 5 hrs to fix

                  Method build_short_edit_script has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def build_short_edit_script(shortest_path)
                      ses = []
                      x, y = 1, 1
                      px, py = 0, 0
                      i = shortest_path.length - 1
                  Severity: Minor
                  Found in lib/onpdiff.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

                  Method migrate_to_new_scheme has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def self.migrate_to_new_scheme(limit = nil)
                      problems = []
                  
                      if SiteSetting.migrate_to_new_scheme
                        max_file_size_kb = SiteSetting.max_image_size_kb.kilobytes
                  Severity: Minor
                  Found in app/models/optimized_image.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

                  Method show_in_site has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def show_in_site(hostname)
                  
                      username = params[:username].to_s
                      return render_blank unless user = User.find_by(username_lower: username.downcase)
                  
                  
                  Severity: Minor
                  Found in app/controllers/user_avatars_controller.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

                  Method digest has a Cognitive Complexity of 35 (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 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

                  Method send_notification_email has 131 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 5 hrs to fix
                    Severity
                    Category
                    Status
                    Source
                    Language