cfabianski/json_translate

View on GitHub

Showing 3 of 3 total issues

Method translates has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def translates(*attrs, allow_blank: false)
      include InstanceMethods

      class_attribute :translated_attribute_names, :permitted_translated_attributes

Severity: Minor
Found in lib/json_translate/translates.rb - About 1 hr to fix

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

          def write_json_translation(attr_name, value, locale: I18n.locale, allow_blank:)
            value = allow_blank ? value : value.presence
            translation_store = "#{attr_name}#{SUFFIX}"
            translations = public_send(translation_store) || {}
            translation_store_will_change!(translation_store) unless translations[locale.to_s] == value
    Severity: Minor
    Found in lib/json_translate/translates/instance_methods.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 read_json_translation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def read_json_translation(attr_name, locale: I18n.locale, fallback: true, **params)
            translations = public_send("#{attr_name}#{SUFFIX}") || {}
    
            selected_locale = locale
            if fallback
    Severity: Minor
    Found in lib/json_translate/translates/instance_methods.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

    Severity
    Category
    Status
    Source
    Language