lib/csv/table.rb

Summary

Maintainability
C
1 day
Test Coverage
A
96%

Method []= has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    def []=(index_or_header, value)
      if @mode == :row or  # by index
         (@mode == :col_or_row and index_or_header.is_a? Integer)
        if value.is_a? Array
          @table[index_or_header] = Row.new(headers, value)
Severity: Minor
Found in lib/csv/table.rb - About 3 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 Table has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Table
    # :call-seq:
    #   CSV::Table.new(array_of_rows, headers = nil) -> csv_table
    #
    # Returns a new \CSV::Table object.
Severity: Minor
Found in lib/csv/table.rb - About 2 hrs to fix

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

        def delete(*indexes_or_headers)
          if indexes_or_headers.empty?
            raise ArgumentError, "wrong number of arguments (given 0, expected 1+)"
          end
          deleted_values = indexes_or_headers.map do |index_or_header|
    Severity: Minor
    Found in lib/csv/table.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 delete_if has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def delete_if(&block)
          return enum_for(__method__) { @mode == :row or @mode == :col_or_row ? size : headers.size } unless block_given?
    
          if @mode == :row or @mode == :col_or_row  # by index
            @table.delete_if(&block)
    Severity: Minor
    Found in lib/csv/table.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 []= has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def []=(index_or_header, value)
          if @mode == :row or  # by index
             (@mode == :col_or_row and index_or_header.is_a? Integer)
            if value.is_a? Array
              @table[index_or_header] = Row.new(headers, value)
    Severity: Minor
    Found in lib/csv/table.rb - About 1 hr to fix

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

          def each(&block)
            return enum_for(__method__) { @mode == :col ? headers.size : size } unless block_given?
      
            if @mode == :col
              headers.each.with_index do |header, i|
      Severity: Minor
      Found in lib/csv/table.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 to_csv has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def to_csv(write_headers: true, limit: nil, **options)
            array = write_headers ? [headers.to_csv(**options)] : []
            limit ||= @table.size
            limit = @table.size + 1 + limit if limit < 0
            limit = 0 if limit < 0
      Severity: Minor
      Found in lib/csv/table.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 @mode == :row or  # by indices
               ( @mode == :col_or_row and indices_or_headers.all? do |index|
                                            index.is_a?(Integer)         or
                                            ( index.is_a?(Range)         and
                                              index.first.is_a?(Integer) and
      Severity: Major
      Found in lib/csv/table.rb - About 40 mins to fix

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

            def dig(index_or_header, *index_or_headers)
              value = self[index_or_header]
              if value.nil?
                nil
              elsif index_or_headers.empty?
        Severity: Minor
        Found in lib/csv/table.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 values_at has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def values_at(*indices_or_headers)
              if @mode == :row or  # by indices
                 ( @mode == :col_or_row and indices_or_headers.all? do |index|
                                              index.is_a?(Integer)         or
                                              ( index.is_a?(Range)         and
        Severity: Minor
        Found in lib/csv/table.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