maa123/mastodon

View on GitHub
lib/mastodon/cli/maintenance.rb

Summary

Maintainability
D
2 days
Test Coverage

File maintenance.rb has 538 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_relative 'base'

module Mastodon::CLI
  class Maintenance < Base
    MIN_SUPPORTED_VERSION = 2019_10_01_213028
Severity: Major
Found in lib/mastodon/cli/maintenance.rb - About 1 day to fix

    Class Maintenance has 32 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Maintenance < Base
        MIN_SUPPORTED_VERSION = 2019_10_01_213028
        MAX_SUPPORTED_VERSION = 2023_09_07_150100
    
        # Stubs to enjoy ActiveRecord queries while not depending on a particular
    Severity: Minor
    Found in lib/mastodon/cli/maintenance.rb - About 4 hrs to fix

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

            def merge_with!(other_account)
              # Since it's the same remote resource, the remote resource likely
              # already believes we are following/blocking, so it's safe to
              # re-attribute the relationships too. However, during the presence
              # of the index bug users could have *also* followed the reference
      Severity: Minor
      Found in lib/mastodon/cli/maintenance.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 merge_statuses! has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def merge_statuses!(main_status, duplicate_status)
            owned_classes = [Favourite, Mention, Poll]
            owned_classes << Bookmark if ActiveRecord::Base.connection.table_exists?(:bookmarks)
            owned_classes.each do |klass|
              klass.where(status_id: duplicate_status.id).find_each do |record|
      Severity: Minor
      Found in lib/mastodon/cli/maintenance.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 merge_with! has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def merge_with!(other_account)
              # Since it's the same remote resource, the remote resource likely
              # already believes we are following/blocking, so it's safe to
              # re-attribute the relationships too. However, during the presence
              # of the index bug users could have *also* followed the reference
      Severity: Minor
      Found in lib/mastodon/cli/maintenance.rb - About 1 hr to fix

        Method fix_duplicates has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def fix_duplicates
              if ActiveRecord::Migrator.current_version < MIN_SUPPORTED_VERSION
                say 'Your version of the database schema is too old and is not supported by this script.', :red
                say 'Please update to at least Mastodon 3.0.0 before running this script.', :red
                exit(1)
        Severity: Minor
        Found in lib/mastodon/cli/maintenance.rb - About 1 hr to fix

          Method deduplicate_local_accounts! has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def deduplicate_local_accounts!(accounts)
                accounts = accounts.sort_by(&:id).reverse
          
                say "Multiple local accounts were found for username '#{accounts.first.username}'.", :yellow
                say 'All those accounts are distinct accounts but only the most recently-created one is fully-functional.', :yellow
          Severity: Minor
          Found in lib/mastodon/cli/maintenance.rb - About 1 hr to fix

            Method deduplicate_users! has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def deduplicate_users!
                  remove_index_if_exists!(:users, 'index_users_on_confirmation_token')
                  remove_index_if_exists!(:users, 'index_users_on_email')
                  remove_index_if_exists!(:users, 'index_users_on_remember_token')
                  remove_index_if_exists!(:users, 'index_users_on_reset_password_token')
            Severity: Minor
            Found in lib/mastodon/cli/maintenance.rb - About 1 hr to fix

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

                  def fix_duplicates
                    if ActiveRecord::Migrator.current_version < MIN_SUPPORTED_VERSION
                      say 'Your version of the database schema is too old and is not supported by this script.', :red
                      say 'Please update to at least Mastodon 3.0.0 before running this script.', :red
                      exit(1)
              Severity: Minor
              Found in lib/mastodon/cli/maintenance.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 deduplicate_accounts! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def deduplicate_accounts!
                    remove_index_if_exists!(:accounts, 'index_accounts_on_username_and_domain_lower')
              
                    say 'Deduplicating accounts… for local accounts, you will be asked to chose which account to keep unchanged.'
              
              
              Severity: Minor
              Found in lib/mastodon/cli/maintenance.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