mashirozx/mastodon

View on GitHub
app/models/status.rb

Summary

Maintainability
D
2 days
Test Coverage

Class Status has 67 methods (exceeds 20 allowed). Consider refactoring.
Open

class Status < ApplicationRecord
  before_destroy :unlink_from_conversations

  include Discard::Model
  include Paginable
Severity: Major
Found in app/models/status.rb - About 1 day to fix

    File status.rb has 464 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Status < ApplicationRecord
      before_destroy :unlink_from_conversations
    
      include Discard::Model
      include Paginable
    Severity: Minor
    Found in app/models/status.rb - About 7 hrs to fix

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

        def self._insert_record(values)
          if values.is_a?(Hash) && values['reblog_of_id'].present?
            primary_key = self.primary_key
            primary_key_value = nil
      
      
      Severity: Minor
      Found in app/models/status.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 set_conversation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_conversation
          self.thread = thread.reblog if thread&.reblog?
      
          self.reply = !(in_reply_to_id.nil? && thread.nil?) unless reply
      
      
      Severity: Minor
      Found in app/models/status.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 permitted_for has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def permitted_for(target_account, account)
            visibility = [:public, :unlisted]
      
            if account.nil?
              where(visibility: visibility).without_local_only
      Severity: Minor
      Found in app/models/status.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

      Consider simplifying this complex logical expression.
      Open

          if preloaded.nil?
            ids += mentions.where(account: Account.local, silent: false).pluck(:account_id)
            ids += favourites.where(account: Account.local).pluck(:account_id)
            ids += reblogs.where(account: Account.local).pluck(:account_id)
            ids += bookmarks.where(account: Account.local).pluck(:account_id)
      Severity: Major
      Found in app/models/status.rb - About 40 mins to fix

        Method set_visibility has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def set_visibility
            self.visibility = reblog.visibility if reblog? && visibility.nil?
            self.visibility = (account.locked? ? :private : :public) if visibility.nil?
            self.sensitive  = false if sensitive.nil?
          end
        Severity: Minor
        Found in app/models/status.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 from_text has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def from_text(text)
              return [] if text.blank?
        
              text.scan(FetchLinkCardService::URL_PATTERN).map(&:second).uniq.filter_map do |url|
                status = begin
        Severity: Minor
        Found in app/models/status.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 searchable_by has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def searchable_by(preloaded = nil)
            ids = []
        
            ids << account_id if local?
        
        
        Severity: Minor
        Found in app/models/status.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 unlink_from_conversations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def unlink_from_conversations
            return unless direct_visibility?
        
            mentioned_accounts = (association(:mentions).loaded? ? mentions : mentions.includes(:account)).map(&:account)
            inbox_owners       = mentioned_accounts.select(&:local?) + (account.local? ? [account] : [])
        Severity: Minor
        Found in app/models/status.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