lib/csv.rb

Summary

Maintainability
F
4 days
Test Coverage
A
93%

File csv.rb has 655 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "forwardable"
require "date"
require "stringio"

require_relative "csv/fields_converter"
Severity: Major
Found in lib/csv.rb - About 1 day to fix

    Class CSV has 63 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class CSV
    
      # The error thrown when the parser encounters illegal CSV formatting.
      class MalformedCSVError < RuntimeError
        attr_reader :line_number
    Severity: Major
    Found in lib/csv.rb - About 1 day to fix

      Method initialize has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def initialize(data,
                       col_sep: ",",
                       row_sep: :auto,
                       quote_char: '"',
                       field_size_limit: nil,
      Severity: Major
      Found in lib/csv.rb - About 2 hrs to fix

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

          def initialize(data,
                         col_sep: ",",
                         row_sep: :auto,
                         quote_char: '"',
                         field_size_limit: nil,
        Severity: Minor
        Found in lib/csv.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 generate_line has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def generate_line(row, **options)
              options = {row_sep: InputRecordSeparator.value}.merge(options)
              str = +""
              if options[:encoding]
                str.force_encoding(options[:encoding])
        Severity: Minor
        Found in lib/csv.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 inspect has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

          def inspect
            str = ["#<", self.class.to_s, " io_type:"]
            # show type of wrapped IO
            if    @io == $stdout then str << "$stdout"
            elsif @io == $stdin  then str << "$stdin"
        Severity: Minor
        Found in lib/csv.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 open has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def open(filename, mode="r", **options)
              # wrap a File opened with the remaining +args+ with no newline
              # decorator
              file_opts = {}
              have_encoding_options = (options.key?(:encoding) or
        Severity: Minor
        Found in lib/csv.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 open has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def open(filename, mode="r", **options)
              # wrap a File opened with the remaining +args+ with no newline
              # decorator
              file_opts = {}
              have_encoding_options = (options.key?(:encoding) or
        Severity: Minor
        Found in lib/csv.rb - About 1 hr to fix

          Method filter has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def filter(input=nil, output=nil, **options)
                # parse options for input, output, or both
                in_options, out_options = Hash.new, {row_sep: InputRecordSeparator.value}
                options.each do |key, value|
                  case key
          Severity: Minor
          Found in lib/csv.rb - About 1 hr to fix

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

                def filter(input=nil, output=nil, **options)
                  # parse options for input, output, or both
                  in_options, out_options = Hash.new, {row_sep: InputRecordSeparator.value}
                  options.each do |key, value|
                    case key
            Severity: Minor
            Found in lib/csv.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 inspect has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def inspect
                str = ["#<", self.class.to_s, " io_type:"]
                # show type of wrapped IO
                if    @io == $stdout then str << "$stdout"
                elsif @io == $stdin  then str << "$stdin"
            Severity: Minor
            Found in lib/csv.rb - About 1 hr to fix

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

                def headers
                  if @writer
                    @writer.headers
                  else
                    parsed_headers = parser.headers
              Severity: Minor
              Found in lib/csv.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 generate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def generate(str=nil, **options)
                    encoding = options[:encoding]
                    # add a default empty String, if none was given
                    if str
                      str = StringIO.new(str)
              Severity: Minor
              Found in lib/csv.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 determine_encoding has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def determine_encoding(encoding, internal_encoding)
                  # honor the IO encoding if we can, otherwise default to ASCII-8BIT
                  io_encoding = raw_encoding
                  return io_encoding if io_encoding
              
              
              Severity: Minor
              Found in lib/csv.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

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                  begin
                    str.join('')
                  rescue  # any encoding error
                    str.map do |s|
                      e = Encoding::Converter.asciicompat_encoding(s.encoding)
              Severity: Minor
              Found in lib/csv.rb and 1 other location - About 20 mins to fix
              lib/csv/row.rb on lines 747..753

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 27.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status