kputnam/stupidedi

View on GitHub
lib/stupidedi/parser/constraint_table.rb

Summary

Maintainability
D
2 days
Test Coverage

Method matches has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

        def matches(segment_tok, strict, mode)
          invalid = true  # Were all present possibly distinguishing elements invalid?
          present = false # Were any possibly distinguishing elements present?

          disjoint, distinct = basis(@instructions, mode)
Severity: Minor
Found in lib/stupidedi/parser/constraint_table.rb - About 6 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 matches has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def matches(segment_tok, strict, mode)
          invalid = true  # Were all present possibly distinguishing elements invalid?
          present = false # Were any possibly distinguishing elements present?

          disjoint, distinct = basis(@instructions, mode)
Severity: Minor
Found in lib/stupidedi/parser/constraint_table.rb - About 1 hr to fix

    Method build_distinct has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

            def build_distinct(total, n, m, instructions)
              if total.finite?
                # The sum of all allowed value sets is finite, so we know that each
                # individual allowed value set is finite (we can iterate over it).
                map = Hash.new{|h,k| h[k] = [] }
    Severity: Minor
    Found in lib/stupidedi/parser/constraint_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 build_disjoint has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

            def build_disjoint(total, n, m, instructions)
              if total.finite?
                # The sum of all allowed value sets is finite, so we know that each
                # individual allowed value set is finite (we can iterate over it).
                map = Hash.new
    Severity: Minor
    Found in lib/stupidedi/parser/constraint_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 basis has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def basis(instructions, mode)
              @__basis[mode] ||= begin
                # When inserting segments, given a choice between two otherwise
                # equivalent instructions, prefer the one with smallest `pop_count`.
                # For example, when inserting an HL*20 in X221 835, the new 2000A
    Severity: Minor
    Found in lib/stupidedi/parser/constraint_table.rb - About 1 hr to fix

      Method build_distinct has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def build_distinct(total, n, m, instructions)
                if total.finite?
                  # The sum of all allowed value sets is finite, so we know that each
                  # individual allowed value set is finite (we can iterate over it).
                  map = Hash.new{|h,k| h[k] = [] }
      Severity: Minor
      Found in lib/stupidedi/parser/constraint_table.rb - About 1 hr to fix

        Method build_disjoint has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def build_disjoint(total, n, m, instructions)
                  if total.finite?
                    # The sum of all allowed value sets is finite, so we know that each
                    # individual allowed value set is finite (we can iterate over it).
                    map = Hash.new
        Severity: Minor
        Found in lib/stupidedi/parser/constraint_table.rb - About 1 hr to fix

          Method deconstruct has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                  def deconstruct(element_toks, m, n)
                    element_tok = element_toks.at(m)
                    element_tok = element_tok.element_toks.at(0) if element_tok.try(:repeated?)
          
                    if element_tok.blank?
          Severity: Minor
          Found in lib/stupidedi/parser/constraint_table.rb - About 35 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 build has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def build(instructions)
                  if instructions.length <= 1
                    ConstraintTable::Stub.new(instructions)
                  elsif instructions.any?{|i| i.segment_use.nil? } and
                    not instructions.all?{|i| i.segment_use.nil? }
          Severity: Minor
          Found in lib/stupidedi/parser/constraint_table.rb - About 35 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

                      map = Hash.new{|h,k| h[k] = instructions }
          
                      instructions.each do |i|
                        element_use = i.segment_use.definition.element_uses.at(n)
                        unless m.nil?
          Severity: Major
          Found in lib/stupidedi/parser/constraint_table.rb and 1 other location - About 1 hr to fix
          lib/stupidedi/parser/constraint_table.rb on lines 397..415

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

          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

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

                      map = Hash.new{|h,k| h[k] = instructions }
          
                      instructions.each do |i|
                        element_use  = i.segment_use.definition.element_uses.at(n)
          
          
          Severity: Major
          Found in lib/stupidedi/parser/constraint_table.rb and 1 other location - About 1 hr to fix
          lib/stupidedi/parser/constraint_table.rb on lines 351..368

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

          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

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

                          if strict
                            designator = "#{segment_tok.id}#{"%02d" % (n + 1)}"
                            designator = designator + "-%02d" % (m + 1) unless m.nil?
          
                            raise ArgumentError,
          Severity: Minor
          Found in lib/stupidedi/parser/constraint_table.rb and 1 other location - About 35 mins to fix
          lib/stupidedi/parser/constraint_table.rb on lines 181..186

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

          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

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

                          if strict
                            designator = "#{segment_tok.id}#{"%02d" % (n + 1)}"
                            designator = designator + "-%02d" % (m + 1) unless m.nil?
          
                            raise ArgumentError,
          Severity: Minor
          Found in lib/stupidedi/parser/constraint_table.rb and 1 other location - About 35 mins to fix
          lib/stupidedi/parser/constraint_table.rb on lines 144..149

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

          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