mashirozx/mastodon

View on GitHub
app/services/post_status_service.rb

Summary

Maintainability
C
1 day
Test Coverage

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

class PostStatusService < BaseService
  include Redisable
  include LanguagesHelper

  MIN_SCHEDULE_OFFSET = 5.minutes.freeze
Severity: Minor
Found in app/services/post_status_service.rb - About 3 hrs to fix

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

      def preprocess_attributes!
        @sensitive    = (@options[:sensitive].nil? ? @account.user&.setting_default_sensitive : @options[:sensitive]) || @options[:spoiler_text].present?
        @text         = @options.delete(:spoiler_text) if @text.blank? && @options[:spoiler_text].present?
        @visibility   = @options[:visibility] || @account.user&.setting_default_privacy
        @visibility   = :unlisted if @visibility&.to_sym == :public && @account.silenced?
    Severity: Minor
    Found in app/services/post_status_service.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 process_remote_attachments has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      def process_remote_attachments
        # IMAGE: [https://s3.mashiro.top/view/2022/02/24/6f3f209aa55e3083f0659ecb62448fc0.jpg]
        image_array = @text.scan(/IMAGE:\s*\[\s*((?:https|http):\/\/.+?)\s*\](?:\s*\{\s*((?:https|http):\/\/.+?)\s*\})*/)
        video_array = @text.scan(/VIDEO:\s*\[\s*((?:https|http):\/\/.+?)\s*\](?:\s*\{\s*((?:https|http):\/\/.+?)\s*\})*/)
    
    
    Severity: Minor
    Found in app/services/post_status_service.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 process_remote_attachments has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def process_remote_attachments
        # IMAGE: [https://s3.mashiro.top/view/2022/02/24/6f3f209aa55e3083f0659ecb62448fc0.jpg]
        image_array = @text.scan(/IMAGE:\s*\[\s*((?:https|http):\/\/.+?)\s*\](?:\s*\{\s*((?:https|http):\/\/.+?)\s*\})*/)
        video_array = @text.scan(/VIDEO:\s*\[\s*((?:https|http):\/\/.+?)\s*\](?:\s*\{\s*((?:https|http):\/\/.+?)\s*\})*/)
    
    
    Severity: Minor
    Found in app/services/post_status_service.rb - About 1 hr to fix

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

        def validate_media!
          if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable)
            @media = []
            return
          end
      Severity: Minor
      Found in app/services/post_status_service.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

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

        def call(account, options = {})
          @account     = account
          @options     = options
          @text        = @options[:text] || ''
          @in_reply_to = @options[:thread]
      Severity: Minor
      Found in app/services/post_status_service.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