extern/json/lib/json/pure/parser.rb

Summary

Maintainability
F
4 days
Test Coverage

Method parse_object has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
Open

      def parse_object
        raise NestingError, "nesting of #@current_nesting is too deep" if
          @max_nesting.nonzero? && @current_nesting > @max_nesting
        result = @object_class.new
        delim = false
Severity: Minor
Found in extern/json/lib/json/pure/parser.rb - About 5 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 parse_string has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

      def parse_string
        if scan(STRING)
          return '' if self[1].empty?
          string = self[1].gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c|
            if u = UNESCAPE_MAP[$&[1]]
Severity: Minor
Found in extern/json/lib/json/pure/parser.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

File parser.rb has 317 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'strscan'

module JSON
  module Pure
    # This class implements the JSON parser that is used to parse a JSON string
Severity: Minor
Found in extern/json/lib/json/pure/parser.rb - About 3 hrs to fix

    Consider simplifying this complex logical expression.
    Open

              if source.encoding == ::Encoding::ASCII_8BIT
                b = source[0, 4].bytes.to_a
                source =
                  case
                  when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
    Severity: Critical
    Found in extern/json/lib/json/pure/parser.rb - About 2 hrs to fix

      Consider simplifying this complex logical expression.
      Open

              if defined?(::Encoding)
                if source.encoding == ::Encoding::ASCII_8BIT
                  b = source[0, 4].bytes.to_a
                  source =
                    case
      Severity: Critical
      Found in extern/json/lib/json/pure/parser.rb - About 2 hrs to fix

        Method parse has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

              def parse
                reset
                obj = nil
                if @quirks_mode
                  while !eos? && skip(IGNORE)
        Severity: Minor
        Found in extern/json/lib/json/pure/parser.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 parse_array has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

              def parse_array
                raise NestingError, "nesting of #@current_nesting is too deep" if
                  @max_nesting.nonzero? && @current_nesting > @max_nesting
                result = @array_class.new
                delim = false
        Severity: Minor
        Found in extern/json/lib/json/pure/parser.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 parse_object has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def parse_object
                raise NestingError, "nesting of #@current_nesting is too deep" if
                  @max_nesting.nonzero? && @current_nesting > @max_nesting
                result = @object_class.new
                delim = false
        Severity: Minor
        Found in extern/json/lib/json/pure/parser.rb - About 1 hr to fix

          Method convert_encoding has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def convert_encoding(source)
                  if source.respond_to?(:to_str)
                    source = source.to_str
                  else
                    raise TypeError, "#{source.inspect} is not like a string"
          Severity: Minor
          Found in extern/json/lib/json/pure/parser.rb - About 1 hr to fix

            Method convert_encoding has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def convert_encoding(source)
                    if source.respond_to?(:to_str)
                      source = source.to_str
                    else
                      raise TypeError, "#{source.inspect} is not like a string"
            Severity: Minor
            Found in extern/json/lib/json/pure/parser.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 initialize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                  def initialize(source, opts = {})
                    opts ||= {}
                    unless @quirks_mode = opts[:quirks_mode]
                      source = convert_encoding source
                    end
            Severity: Minor
            Found in extern/json/lib/json/pure/parser.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 parse_value has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def parse_value
                    case
                    when scan(FLOAT)
                      Float(self[1])
                    when scan(INTEGER)
            Severity: Minor
            Found in extern/json/lib/json/pure/parser.rb - About 1 hr to fix

              Method parse has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def parse
                      reset
                      obj = nil
                      if @quirks_mode
                        while !eos? && skip(IGNORE)
              Severity: Minor
              Found in extern/json/lib/json/pure/parser.rb - About 1 hr to fix

                Method parse_string has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def parse_string
                        if scan(STRING)
                          return '' if self[1].empty?
                          string = self[1].gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c|
                            if u = UNESCAPE_MAP[$&[1]]
                Severity: Minor
                Found in extern/json/lib/json/pure/parser.rb - About 1 hr to fix

                  Method parse_array has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        def parse_array
                          raise NestingError, "nesting of #@current_nesting is too deep" if
                            @max_nesting.nonzero? && @current_nesting > @max_nesting
                          result = @array_class.new
                          delim = false
                  Severity: Minor
                  Found in extern/json/lib/json/pure/parser.rb - About 1 hr to fix

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

                                  when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
                                    source.dup.force_encoding(::Encoding::UTF_32BE).encode!(::Encoding::UTF_8)
                    Severity: Minor
                    Found in extern/json/lib/json/pure/parser.rb and 1 other location - About 30 mins to fix
                    extern/json/lib/json/pure/parser.rb on lines 163..164

                    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 32.

                    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

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

                                  when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
                                    source.dup.force_encoding(::Encoding::UTF_32LE).encode!(::Encoding::UTF_8)
                    Severity: Minor
                    Found in extern/json/lib/json/pure/parser.rb and 1 other location - About 30 mins to fix
                    extern/json/lib/json/pure/parser.rb on lines 159..160

                    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 32.

                    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

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

                                when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
                                  JSON.iconv('utf-8', 'utf-32be', b)
                    Severity: Minor
                    Found in extern/json/lib/json/pure/parser.rb and 1 other location - About 25 mins to fix
                    extern/json/lib/json/pure/parser.rb on lines 182..183

                    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 29.

                    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

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

                                when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
                                  JSON.iconv('utf-8', 'utf-32le', b)
                    Severity: Minor
                    Found in extern/json/lib/json/pure/parser.rb and 1 other location - About 25 mins to fix
                    extern/json/lib/json/pure/parser.rb on lines 178..179

                    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 29.

                    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

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

                                  when b.size >= 4 && b[0] == 0 && b[2] == 0
                                    source.dup.force_encoding(::Encoding::UTF_16BE).encode!(::Encoding::UTF_8)
                    Severity: Minor
                    Found in extern/json/lib/json/pure/parser.rb and 1 other location - About 15 mins to fix
                    extern/json/lib/json/pure/parser.rb on lines 165..166

                    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 26.

                    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

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

                                  when b.size >= 4 && b[1] == 0 && b[3] == 0
                                    source.dup.force_encoding(::Encoding::UTF_16LE).encode!(::Encoding::UTF_8)
                    Severity: Minor
                    Found in extern/json/lib/json/pure/parser.rb and 1 other location - About 15 mins to fix
                    extern/json/lib/json/pure/parser.rb on lines 161..162

                    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 26.

                    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