translation/rails

View on GitHub
lib/translation_io/flat_hash.rb

Summary

Maintainability
D
1 day
Test Coverage
A
100%

Method build_hash_with_flat has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
Open

      def build_hash_with_flat(hash, key_string, value)
        current_object = hash
        splitted       = key_string.split(/\.|\[/, 2)
        current_key    = splitted[0] # first is always a hash
        key_string     = splitted[1]
Severity: Minor
Found in lib/translation_io/flat_hash.rb - About 7 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 build_hash_with_flat has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def build_hash_with_flat(hash, key_string, value)
        current_object = hash
        splitted       = key_string.split(/\.|\[/, 2)
        current_key    = splitted[0] # first is always a hash
        key_string     = splitted[1]
Severity: Minor
Found in lib/translation_io/flat_hash.rb - About 1 hr to fix

    Method gsub_keys! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def gsub_keys!(h, from_1, from_2, to_1, to_2)
            if h.is_a?(Hash)
              h.keys.each do |key|
                if key.to_s.include?(from_1) || key.to_s.include?(from_2)
                  new_key = key.to_s.gsub(from_1, to_1).gsub(from_2, to_2)
    Severity: Minor
    Found in lib/translation_io/flat_hash.rb - About 55 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 no_key?(current_object, current_key)
                    current_object[current_key] = {}
                  end
    Severity: Major
    Found in lib/translation_io/flat_hash.rb - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                    if key_string.count(']') > key_string.count('[')
                      key_string = '[' + key_string
                    end
      Severity: Major
      Found in lib/translation_io/flat_hash.rb - About 45 mins to fix

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

              def remove_reserved_keys!(h)
                if h.is_a?(Hash)
                  h.keys.each do |key|
                    if [TrueClass, FalseClass].include?(key.class)
                      # # This warning is commented because Rails admin uses bad keys: https://github.com/sferik/rails_admin/blob/master/config/locales/rails_admin.en.yml
        Severity: Minor
        Found in lib/translation_io/flat_hash.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

                        current_object[array_pos] = value if current_object.is_a?(Array)
        Severity: Major
        Found in lib/translation_io/flat_hash.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                        current_object[new_key] = value if current_object.is_a?(Hash)
          Severity: Major
          Found in lib/translation_io/flat_hash.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                          if no_key?(current_object, current_key)
                            current_object[current_key] = {}
                          end
            Severity: Major
            Found in lib/translation_io/flat_hash.rb - About 45 mins to fix

              Method gsub_keys! has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                    def gsub_keys!(h, from_1, from_2, to_1, to_2)
              Severity: Minor
              Found in lib/translation_io/flat_hash.rb - About 35 mins to fix

                There are no issues that match your filters.

                Category
                Status