maa123/mastodon

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

Summary

Maintainability
F
4 days
Test Coverage

File accounts.rb has 554 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'set'
require_relative 'base'

module Mastodon::CLI
  class Accounts < Base
Severity: Major
Found in lib/mastodon/cli/accounts.rb - About 1 day to fix

    Method refresh has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def refresh(*usernames)
          if options[:domain] || options[:all]
            scope  = Account.remote
            scope  = scope.where(domain: options[:domain]) if options[:domain]
    
    
    Severity: Minor
    Found in lib/mastodon/cli/accounts.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 migrate has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def migrate(username)
          if options[:replay].present? && options[:target].present?
            say('Use --replay or --target, not both', :red)
            exit(1)
          end
    Severity: Minor
    Found in lib/mastodon/cli/accounts.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 cull has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def cull(*domains)
          skip_threshold = 7.days.ago
          skip_domains   = Concurrent::Set.new
    
          query = Account.remote.where(protocol: :activitypub)
    Severity: Minor
    Found in lib/mastodon/cli/accounts.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 modify has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def modify(username)
          user = Account.find_local(username)&.user
    
          if user.nil?
            say('No user with such username', :red)
    Severity: Minor
    Found in lib/mastodon/cli/accounts.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 create has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def create(username)
          role_id  = nil
    
          if options[:role]
            role = UserRole.find_by(name: options[:role])
    Severity: Minor
    Found in lib/mastodon/cli/accounts.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 migrate has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def migrate(username)
          if options[:replay].present? && options[:target].present?
            say('Use --replay or --target, not both', :red)
            exit(1)
          end
    Severity: Minor
    Found in lib/mastodon/cli/accounts.rb - About 1 hr to fix

      Method reset_relationships has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def reset_relationships(username)
            unless options[:follows] || options[:followers]
              say('Please specify either --follows or --followers, or both', :red)
              exit(1)
            end
      Severity: Minor
      Found in lib/mastodon/cli/accounts.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 prune has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def prune
            query = Account.remote.where.not(actor_type: %i(Application Service))
            query = query.where('NOT EXISTS (SELECT 1 FROM mentions WHERE account_id = accounts.id)')
            query = query.where('NOT EXISTS (SELECT 1 FROM favourites WHERE account_id = accounts.id)')
            query = query.where('NOT EXISTS (SELECT 1 FROM statuses WHERE account_id = accounts.id)')
      Severity: Minor
      Found in lib/mastodon/cli/accounts.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 reset_relationships has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def reset_relationships(username)
            unless options[:follows] || options[:followers]
              say('Please specify either --follows or --followers, or both', :red)
              exit(1)
            end
      Severity: Minor
      Found in lib/mastodon/cli/accounts.rb - About 1 hr to fix

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

            def create(username)
              role_id  = nil
        
              if options[:role]
                role = UserRole.find_by(name: options[:role])
        Severity: Minor
        Found in lib/mastodon/cli/accounts.rb - About 1 hr to fix

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

              def refresh(*usernames)
                if options[:domain] || options[:all]
                  scope  = Account.remote
                  scope  = scope.where(domain: options[:domain]) if options[:domain]
          
          
          Severity: Minor
          Found in lib/mastodon/cli/accounts.rb - About 1 hr to fix

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

                def delete(username = nil)
                  if username.present? && options[:email].present?
                    say('Use username or --email, not both', :red)
                    exit(1)
                  elsif username.blank? && options[:email].blank?
            Severity: Minor
            Found in lib/mastodon/cli/accounts.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 modify has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def modify(username)
                  user = Account.find_local(username)&.user
            
                  if user.nil?
                    say('No user with such username', :red)
            Severity: Minor
            Found in lib/mastodon/cli/accounts.rb - About 1 hr to fix

              Method approve has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def approve(username = nil)
                    if options[:all]
                      User.pending.find_each(&:approve!)
                      say('OK', :green)
                    elsif options[:number]&.positive?
              Severity: Minor
              Found in lib/mastodon/cli/accounts.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

              There are no issues that match your filters.

              Category
              Status