openjaf/cenit

View on GitHub
lib/cenit/utility.rb

Summary

Maintainability
F
1 wk
Test Coverage

Method save_references has a Cognitive Complexity of 103 (exceeds 5 allowed). Consider refactoring.
Open

      def save_references(record, options, saved, visited = Set.new)
        # TODO: Propagate error to parent relation...
        return true if visited.include?(record)
        visited << record
        if record.is_a?(Setup::Collection)
Severity: Minor
Found in lib/cenit/utility.rb - About 2 days 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 bind_references has a Cognitive Complexity of 103 (exceeds 5 allowed). Consider refactoring.
Open

      def bind_references(record, options = {})
        options ||= {}
        references = {}
        for_each_node_starting_at(record, options) do |obj|
          ::Setup::Optimizer.instance.regist_data_types(obj)
Severity: Minor
Found in lib/cenit/utility.rb - About 2 days 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 utility.rb has 461 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'objspace'

module Cenit
  class Utility

Severity: Minor
Found in lib/cenit/utility.rb - About 7 hrs to fix

    Method for_each_node_starting_at has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
    Open

          def for_each_node_starting_at(record, options = {}, &block)
            stack = options[:stack]
            unless (visited = options[:visited])
              visited = options[:visited] = Set.new
            end
    Severity: Minor
    Found in lib/cenit/utility.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 eql_content? has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

          def eql_content?(a, b, key = nil, &block)
            case a
              when Hash
                if b.is_a?(Hash)
                  if a.size < b.size
    Severity: Minor
    Found in lib/cenit/utility.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 save has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

          def save(record, options = {})
            saved = options[:saved_collector] || Set.new
            if bind_references(record, options.delete(:bind_references))
              success =
                if record.try(:save_self_before_refs)
    Severity: Minor
    Found in lib/cenit/utility.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 find_record has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

          def find_record(conditions, *scopes)
            scopes.each do |original_scope|
              scope = original_scope
              match_conditions = {}
              begin
    Severity: Minor
    Found in lib/cenit/utility.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

    Method bind_references has 88 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def bind_references(record, options = {})
            options ||= {}
            references = {}
            for_each_node_starting_at(record, options) do |obj|
              ::Setup::Optimizer.instance.regist_data_types(obj)
    Severity: Major
    Found in lib/cenit/utility.rb - About 3 hrs to fix

      Method json_object? has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

            def json_object?(obj, options = {})
              case obj
                when Hash
                  if options[:recursive]
                    obj.keys.each { |k| return false unless k.is_a?(String) }
      Severity: Minor
      Found in lib/cenit/utility.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

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

            def match?(obj, criteria)
              criteria.each do |property_name, value|
                property_value =
                  case obj
                    when Hash
      Severity: Minor
      Found in lib/cenit/utility.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 json_value_of has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

            def json_value_of(value)
              return value unless value.is_a?(String)
              value = value.strip
              if value.blank?
                nil
      Severity: Minor
      Found in lib/cenit/utility.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 save_references has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def save_references(record, options, saved, visited = Set.new)
              # TODO: Propagate error to parent relation...
              return true if visited.include?(record)
              visited << record
              if record.is_a?(Setup::Collection)
      Severity: Major
      Found in lib/cenit/utility.rb - About 2 hrs to fix

        Method find_record has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def find_record(conditions, *scopes)
                scopes.each do |original_scope|
                  scope = original_scope
                  match_conditions = {}
                  begin
        Severity: Minor
        Found in lib/cenit/utility.rb - About 2 hrs to fix

          Method save has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def save(record, options = {})
                  saved = options[:saved_collector] || Set.new
                  if bind_references(record, options.delete(:bind_references))
                    success =
                      if record.try(:save_self_before_refs)
          Severity: Minor
          Found in lib/cenit/utility.rb - About 1 hr to fix

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

                  def eql_content?(a, b, key = nil, &block)
                    case a
                      when Hash
                        if b.is_a?(Hash)
                          if a.size < b.size
            Severity: Minor
            Found in lib/cenit/utility.rb - About 1 hr to fix

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

                    def associated_ids(association, criteria)
                      associations =
                        begin
                          association.klass.get_associations
                        rescue
              Severity: Minor
              Found in lib/cenit/utility.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 json_value_of has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def json_value_of(value)
                      return value unless value.is_a?(String)
                      value = value.strip
                      if value.blank?
                        nil
              Severity: Minor
              Found in lib/cenit/utility.rb - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                                  return false unless save_references(value, options, saved, visited)
                Severity: Major
                Found in lib/cenit/utility.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                  unless saved.include?(value)
                                    new_record = value.new_record?
                                    if value.changed?
                                      if value.save(options)
                                        if new_record || value.instance_variable_get(:@dynamically_created)
                  Severity: Major
                  Found in lib/cenit/utility.rb - About 45 mins to fix

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

                          def array_hash_merge(val1, val2, options = {}, &block)
                            if val1.is_a?(Array) && val2.is_a?(Array)
                              if options[:array_uniq]
                                (val2 + val1).uniq(&block)
                              else
                    Severity: Minor
                    Found in lib/cenit/utility.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

                    Avoid deeply nested control flow statements.
                    Open

                                  if (obj = (obj.reload rescue nil))
                    Severity: Major
                    Found in lib/cenit/utility.rb - About 45 mins to fix

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

                            def deep_remove(hash, key)
                              if hash.is_a?(Hash)
                                hash.inject({}) do |h, (k, v)|
                                  h[k] = deep_remove(v, key) unless k == key
                                  h
                      Severity: Minor
                      Found in lib/cenit/utility.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

                      Avoid too many return statements within this method.
                      Open

                                  return a.eql?(b) || (block && block.call(*(block.arity == 3 ? [a, b, key] : [a, b])))
                      Severity: Major
                      Found in lib/cenit/utility.rb - About 30 mins to fix

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

                              def stringfy(obj)
                                if obj.is_a?(Hash)
                                  hash = {}
                                  obj.each { |key, value| hash[key.to_s] = stringfy(value) }
                                  hash
                        Severity: Minor
                        Found in lib/cenit/utility.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

                                      if value.save(options)
                                        if new_record || value.instance_variable_get(:@dynamically_created)
                                          value.instance_variable_set(:@dynamically_created, true)
                                          options[:create_collector] << value if options[:create_collector]
                                        else
                        Severity: Minor
                        Found in lib/cenit/utility.rb and 1 other location - About 45 mins to fix
                        lib/cenit/utility.rb on lines 280..289

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

                        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 value.save(options)
                                              if new_record || value.instance_variable_get(:@dynamically_created)
                                                value.instance_variable_set(:@dynamically_created, true)
                                                options[:create_collector] << value if options[:create_collector]
                                              else
                        Severity: Minor
                        Found in lib/cenit/utility.rb and 1 other location - About 45 mins to fix
                        lib/cenit/utility.rb on lines 251..260

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

                        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