redmine/redmine

View on GitHub
app/models/import.rb

Summary

Maintainability
D
1 day
Test Coverage

Method run has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

  def run(options={})
    max_items = options[:max_items]
    max_time = options[:max_time]
    current = 0
    imported = 0
Severity: Minor
Found in app/models/import.rb - About 4 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

Class Import has 29 methods (exceeds 20 allowed). Consider refactoring.
Open

class Import < ApplicationRecord
  has_many :items, :class_name => 'ImportItem', :dependent => :delete_all
  belongs_to :user
  serialize :settings

Severity: Minor
Found in app/models/import.rb - About 3 hrs to fix

    Method run has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def run(options={})
        max_items = options[:max_items]
        max_time = options[:max_time]
        current = 0
        imported = 0
    Severity: Minor
    Found in app/models/import.rb - About 1 hr to fix

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

        def set_default_settings(options={})
          separator = lu(user, :general_csv_separator)
          wrapper = '"'
          encoding = lu(user, :general_csv_encoding)
          if file_exists?
      Severity: Minor
      Found in app/models/import.rb - About 1 hr to fix

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

          def set_default_settings(options={})
            separator = lu(user, :general_csv_separator)
            wrapper = '"'
            encoding = lu(user, :general_csv_encoding)
            if file_exists?
        Severity: Minor
        Found in app/models/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

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

          def read_rows
            return unless file_exists?
        
            csv_options = {:headers => false}
            csv_options[:encoding] = settings['encoding'].to_s.presence || 'UTF-8'
        Severity: Minor
        Found in app/models/import.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 read_items has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def read_items
            i = 0
            headers = true
            read_rows do |row|
              if i == 0 && headers
        Severity: Minor
        Found in app/models/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

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

          def row_date(row, key)
            if s = row_value(row, key)
              format = settings['date_format']
              format = DATE_FORMATS.first unless DATE_FORMATS.include?(format)
              Date.strptime(s, format) rescue s
        Severity: Minor
        Found in app/models/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

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

          def remove_file
            if file_exists?
              begin
                File.delete filepath
              rescue => e
        Severity: Minor
        Found in app/models/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