thredded/thredded

View on GitHub

Showing 68 of 70 total issues

File database_seeder.rb has 374 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'factory_bot'
require_relative '../../spec/support/features/fake_content'

# rubocop:disable HandleExceptions
begin
Severity: Minor
Found in lib/thredded/database_seeder.rb - About 5 hrs to fix

    Class DatabaseSeeder has 26 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class DatabaseSeeder # rubocop:disable Metrics/ClassLength
        module LogTime
          def self.included(base)
            base.extend ClassMethods
          end
    Severity: Minor
    Found in lib/thredded/database_seeder.rb - About 3 hrs to fix

      Method parse_names has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def parse_names(text) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
            result = []
            current = +''
            in_name = in_quoted = false
            text.each_char do |char|
      Severity: Minor
      Found in app/forms/thredded/private_topic_form.rb - About 2 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 has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def show # rubocop:disable Metrics/MethodLength
            @messageboard = Thredded::Messageboard.first
            fail Thredded::Errors::DatabaseEmpty unless @messageboard
            @user = if thredded_current_user.thredded_anonymous?
                      Thredded.user_class.new(id: 1334, name: 'joe', email: 'joe@example.com')
      Severity: Minor
      Found in app/controllers/thredded/theme_previews_controller.rb - About 1 hr to fix

        Method time_ago has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def time_ago(datetime, default: '-', html_options: {})
              return content_tag :time, default if datetime.nil?
              html_options = html_options.dup
              is_current_year = datetime.year == Time.current.year
              if datetime > 4.days.ago
        Severity: Minor
        Found in app/helpers/thredded/application_helper.rb - About 1 hr 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 has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              log_method_time def create(count: (1..1), topics: seeder.topics) # rubocop:disable Metrics/MethodLength
                log "Creating #{count} additional posts in each topic..."
                topics.flat_map do |topic|
                  last_post_at = random_duration(0..256.hours).ago
                  posts_count = (count.min + rand(count.max + 1))
        Severity: Minor
        Found in lib/thredded/database_seeder.rb - About 1 hr to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            class PrivateTopicMailer < Thredded::BaseMailer
              def message_notification(post_id, emails)
                @post = find_record Thredded::PrivatePost, post_id
                email_details = Thredded::TopicEmailView.new(@post.postable)
                headers['X-SMTPAPI'] = email_details.smtp_api_tag('private_topic_mailer')
          Severity: Major
          Found in app/mailers/thredded/private_topic_mailer.rb and 1 other location - About 1 hr to fix
          app/mailers/thredded/post_mailer.rb on lines 4..19

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 49.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            class PostMailer < Thredded::BaseMailer
              def post_notification(post_id, emails)
                @post = find_record Thredded::Post, post_id
                email_details = Thredded::TopicEmailView.new(@post.postable)
                headers['X-SMTPAPI'] = email_details.smtp_api_tag('post_notification')
          Severity: Major
          Found in app/mailers/thredded/post_mailer.rb and 1 other location - About 1 hr to fix
          app/mailers/thredded/private_topic_mailer.rb on lines 4..19

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 49.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Method grouped has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def self.grouped( # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
                messageboards_scope, user: Thredded::NullUser.new, with_unread_topics_counts: !user.thredded_anonymous?
              )
                scope = messageboards_scope.preload(last_topic: [:last_user])
                  .eager_load(:group)
          Severity: Minor
          Found in app/view_models/thredded/messageboard_group_view.rb - About 1 hr to fix

            Method parse_names has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def parse_names(text) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
                  result = []
                  current = +''
                  in_name = in_quoted = false
                  text.each_char do |char|
            Severity: Minor
            Found in app/forms/thredded/private_topic_form.rb - About 1 hr to fix

              Method create has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                    log_method_time def create(count: 1)
                      log "Creating #{count} private topics..."
                      Array.new(count) do
                        started_by_first_user = [true, false].sample
                        user = started_by_first_user ? seeder.first_user : seeder.users[1..-1].sample
              Severity: Minor
              Found in lib/thredded/database_seeder.rb - About 55 mins 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 render_collection_to_strings_with_cache has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def render_collection_to_strings_with_cache( # rubocop:disable Metrics/ParameterLists
                    view_context, collection:, partial:, expires_in:, render_threads: self.class.render_threads, locals: {}, **opts
                  )
                    template = @lookup_context.find_template(partial, [], true, locals, {})
                    collection = collection.to_a
              Severity: Minor
              Found in lib/thredded/collection_to_strings_with_cache_renderer.rb - About 55 mins 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 has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def save
                    return false unless valid?
                    Thredded::UserPreference.transaction do
                      user_preference.save!
              
              
              Severity: Minor
              Found in app/forms/thredded/user_preferences_form.rb - About 55 mins 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 run! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def run!(post:, moderation_state:, moderator:)
                    Thredded::Post.transaction do
                      post_moderation_record = Thredded::PostModerationRecord.record!(
                        moderator: moderator,
                        post: post,
              Severity: Minor
              Found in app/commands/thredded/moderate_post.rb - About 45 mins 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 find_placeholder_end has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                      def find_placeholder_end(sibling)
                        children = []
                        placeholder_end = nil
                        loop do
                          sibling = sibling.next_sibling
              Severity: Minor
              Found in lib/thredded/html_pipeline/spoiler_tag_filter.rb - About 45 mins 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 call has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                    def call
                      doc.css('a').each do |element|
                        url = element['href'].to_s
                        next unless url.present? && url == element.content && on_its_own_line?(element)
                        onebox_html = render_onebox_with_cache(url)
              Severity: Minor
              Found in lib/thredded/html_pipeline/onebox_filter.rb - About 45 mins 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 grouped has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def self.grouped( # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
                    messageboards_scope, user: Thredded::NullUser.new, with_unread_topics_counts: !user.thredded_anonymous?
                  )
                    scope = messageboards_scope.preload(last_topic: [:last_user])
                      .eager_load(:group)
              Severity: Minor
              Found in app/view_models/thredded/messageboard_group_view.rb - About 35 mins 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 restore has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                    def restore(from = dump_file)
                      case adapter
                      when /postgres/i
                        cmd = [
                          'pg_restore --verbose --clean --no-owner --no-acl',
              Severity: Minor
              Found in lib/thredded/db_tools.rb - About 35 mins 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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  def mark_as_read
                    authorize post, :read?
                    UserPrivateTopicReadState.touch!(thredded_current_user.id, post)
                    respond_to do |format|
                      format.html { redirect_back fallback_location: post_path(post, user: thredded_current_user) }
              Severity: Minor
              Found in app/controllers/thredded/private_posts_controller.rb and 1 other location - About 35 mins to fix
              app/controllers/thredded/posts_controller.rb on lines 57..62

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 34.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  def mark_as_read
                    authorize post, :read?
                    UserTopicReadState.touch!(thredded_current_user.id, post)
                    respond_to do |format|
                      format.html { redirect_back fallback_location: post_path(post, user: thredded_current_user) }
              Severity: Minor
              Found in app/controllers/thredded/posts_controller.rb and 1 other location - About 35 mins to fix
              app/controllers/thredded/private_posts_controller.rb on lines 54..59

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 34.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Severity
              Category
              Status
              Source
              Language