clicrdv/translatable

View on GitHub

Showing 7 of 7 total issues

Method translation_for_serialized has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

      def translation_for_serialized(locale, name, value, build_if_missing = false)

        unless translation_caches["#{locale}_#{name}"]
          engine = self.attributes.has_key?(name) ? nil : JSON
          deserialized_value = engine.nil? ? value : engine.load(value)
Severity: Minor
Found in lib/translatable/active_record/instance_methods.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 translatable has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

      def translatable(*attr_names)

        options = attr_names.extract_options!
        setup_translatable!(options) unless translatable?

Severity: Minor
Found in lib/translatable/active_record/macro.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 with_given_locale has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def with_given_locale(attributes, &block)
        attributes.symbolize_keys! if attributes.respond_to?(:symbolize_keys!)

        locale = respond_to?(:locale=) ? attributes.try(:[], :locale) :
            attributes.try(:delete, :locale)
Severity: Minor
Found in lib/translatable/active_record/instance_methods.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 add_translatable has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def add_translatable(klass)
      if @@translatable.has_key? klass.name
        klass.translated_attribute_names.each do |attr|
          @@translatable[klass.name] << attr unless @@translatable[klass.name].include?(attr)
        end
Severity: Minor
Found in lib/translatable.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 translation_for_serialized has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def translation_for_serialized(locale, name, value, build_if_missing = false)

        unless translation_caches["#{locale}_#{name}"]
          engine = self.attributes.has_key?(name) ? nil : JSON
          deserialized_value = engine.nil? ? value : engine.load(value)
Severity: Minor
Found in lib/translatable/active_record/instance_methods.rb - About 1 hr to fix

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

          def read_attribute(name, options = {}, &block)
            options = {:translated => true, :locale => Translatable.locale}.merge(options)
            if r_translated?(name) and options[:translated]
              serialized_value = super(name) if self.attributes.has_key?(name)
              if translate? && (value = translatable.fetch(options[:locale] || Translatable.locale, name, serialized_value))
    Severity: Minor
    Found in lib/translatable/active_record/instance_methods.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

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

          def translation_for(locale, name, build_if_missing = false)
            unless translation_caches["#{locale}_#{name}"]
              # Fetch translations from database as those in the translation collection may be incomplete
              _translation = translations.detect{|t| t.locale.to_s == locale.to_s && t.key.to_s == name.to_s }
              _translation ||= translations.build(:locale => locale) if build_if_missing
    Severity: Minor
    Found in lib/translatable/active_record/instance_methods.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

    Severity
    Category
    Status
    Source
    Language