discourse/discourse

View on GitHub
app/services/post_alerter.rb

Summary

Maintainability
F
4 days
Test Coverage

File post_alerter.rb has 481 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class PostAlerter
  USER_BATCH_SIZE = 100

  def self.post_created(post, opts = {})
    PostAlerter.new(opts).after_save_post(post, true)
Severity: Minor
Found in app/services/post_alerter.rb - About 7 hrs to fix

    Method create_notification has a Cognitive Complexity of 37 (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

    Class PostAlerter has 39 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class PostAlerter
      USER_BATCH_SIZE = 100
    
      def self.post_created(post, opts = {})
        PostAlerter.new(opts).after_save_post(post, true)
    Severity: Minor
    Found in app/services/post_alerter.rb - About 5 hrs to fix

      Method create_notification has 101 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

        Method notify_post_users has 51 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def notify_post_users(post, notified, include_category_watchers: true, include_tag_watchers: true)
            return unless post.topic
        
            warn_if_not_sidekiq
        
        
        Severity: Major
        Found in app/services/post_alerter.rb - About 2 hrs to fix

          Method after_save_post has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            def after_save_post(post, new_record = false)
              notified = [post.user, post.last_editor].uniq
          
              # mentions (users/groups)
              mentioned_groups, mentioned_users = extract_mentions(post)
          Severity: Minor
          Found in app/services/post_alerter.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 after_save_post has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def after_save_post(post, new_record = false)
              notified = [post.user, post.last_editor].uniq
          
              # mentions (users/groups)
              mentioned_groups, mentioned_users = extract_mentions(post)
          Severity: Minor
          Found in app/services/post_alerter.rb - About 1 hr to fix

            Method notify_group_summary has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def notify_group_summary(user, post)
                @group_stats ||= {}
                stats = (@group_stats[post.topic_id] ||= group_stats(post.topic))
                return unless stats
            
            
            Severity: Minor
            Found in app/services/post_alerter.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 notify_post_users has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def notify_post_users(post, notified, include_category_watchers: true, include_tag_watchers: true)
                return unless post.topic
            
                warn_if_not_sidekiq
            
            
            Severity: Minor
            Found in app/services/post_alerter.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 notify_pm_users has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def notify_pm_users(post, reply_to_user, notified)
                return unless post.topic
            
                warn_if_not_sidekiq
            
            
            Severity: Minor
            Found in app/services/post_alerter.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

            Avoid too many return statements within this method.
            Open

                return if notifier_id && IgnoredUser.where(user_id: user.id, ignored_user_id: notifier_id)
            Severity: Major
            Found in app/services/post_alerter.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                  return if notifier_id && MutedUser.where(user_id: user.id, muted_user_id: notifier_id)
              Severity: Major
              Found in app/services/post_alerter.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                    return if user.staged? && topic.category&.mailinglist_mirror?
                Severity: Major
                Found in app/services/post_alerter.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                        return if GroupUser.where(
                  Severity: Major
                  Found in app/services/post_alerter.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                        return if existing_notification_of_same_type && !should_notify_previous?(user, post, existing_notification_of_same_type, opts)
                    Severity: Major
                    Found in app/services/post_alerter.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                          return if TopicUser.where(
                      Severity: Major
                      Found in app/services/post_alerter.rb - About 30 mins to fix

                        Method expand_group_mentions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def expand_group_mentions(groups, post)
                            return unless post.user && groups
                        
                            Group.mentionable(post.user, include_public: false).where(id: groups.map(&:id)).each do |group|
                              next if group.user_count >= SiteSetting.max_users_notified_per_group_mention
                        Severity: Minor
                        Found in app/services/post_alerter.rb - About 25 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

                        There are no issues that match your filters.

                        Category
                        Status