maa123/mastodon

View on GitHub
app/models/form/import.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Method validate_data has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_data
    return if data.nil?
    return errors.add(:data, I18n.t('imports.errors.too_large')) if data.size > FILE_SIZE_LIMIT
    return errors.add(:data, I18n.t('imports.errors.incompatible_type')) unless default_csv_headers.all? { |header| csv_data.headers.include?(header) }

Severity: Minor
Found in app/models/form/import.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 guessed_type has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def guessed_type
    return :muting if csv_data.headers.include?('Hide notifications')
    return :following if csv_data.headers.include?('Show boosts') || csv_data.headers.include?('Notify on new posts') || csv_data.headers.include?('Languages')
    return :following if data.original_filename&.start_with?('follows') || data.original_filename&.start_with?('following_accounts')
    return :blocking if data.original_filename&.start_with?('blocks') || data.original_filename&.start_with?('blocked_accounts')
Severity: Minor
Found in app/models/form/import.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

Avoid too many return statements within this method.
Open

    return :muting if data.original_filename&.start_with?('mutes') || data.original_filename&.start_with?('muted_accounts')
Severity: Major
Found in app/models/form/import.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

        return :lists if data.original_filename&.start_with?('lists')
    Severity: Major
    Found in app/models/form/import.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

          return :bookmarks if data.original_filename&.start_with?('bookmarks')
      Severity: Major
      Found in app/models/form/import.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

            return :domain_blocking if data.original_filename&.start_with?('domain_blocks') || data.original_filename&.start_with?('blocked_domains')
        Severity: Major
        Found in app/models/form/import.rb - About 30 mins to fix

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

            def csv_data
              return @csv_data if defined?(@csv_data)
          
              csv_converter = lambda do |field, field_info|
                case field_info.header
          Severity: Minor
          Found in app/models/form/import.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