globalize/globalize

View on GitHub

Showing 20 of 23 total issues

Class Migrator has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

      class Migrator
        include Globalize::ActiveRecord::Exceptions

        attr_reader :model
        delegate :translated_attribute_names, :connection, :table_name,
Severity: Minor
Found in lib/globalize/active_record/migration.rb - About 2 hrs to fix

    Method query_attribute has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

          def query_attribute(attr_name)
            unless value = read_attribute(attr_name)
              false
            else
              column = self.class.columns_hash[attr_name]
    Severity: Minor
    Found in lib/patches/active_record/rails4/query_method.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 validate_each has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

          def validate_each(record, attribute, value)
            klass = record.class
            if klass.translates? && klass.translated?(attribute)
              finder_class = klass.translation_class
              finder_table = finder_class.arel_table
    Severity: Minor
    Found in lib/patches/active_record/rails5/uniqueness_validator.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 validate_each has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

          def validate_each(record, attribute, value)
            klass = record.class
            if klass.translates? && klass.translated?(attribute)
              finder_class = klass.translation_class
              relation = build_relation(finder_class, attribute, value).where(locale: Globalize.locale)
    Severity: Minor
    Found in lib/patches/active_record/rails6_1/uniqueness_validator.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 validate_each has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

          def validate_each(record, attribute, value)
            klass = record.class
            if klass.translates? && klass.translated?(attribute)
              finder_class = klass.translation_class
              relation = build_relation(finder_class, attribute, value).where(locale: Globalize.locale)
    Severity: Minor
    Found in lib/patches/active_record/rails5_1/uniqueness_validator.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 has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

          def translation_for(locale, build_if_missing = true)
            unless translation_caches[locale]
              # Fetch translations from database as those in the translation collection may be incomplete
              _translation = translations.detect{|t| t.locale.to_s == locale.to_s}
              _translation ||= translations.with_locale(locale).first unless translations.loaded?
    Severity: Minor
    Found in lib/globalize/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 where_values_hash has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

            def where_values_hash(*args)
              return super unless respond_to?(:translations_table_name)
              equalities = respond_to?(:with_default_scope) ? with_default_scope.where_values : where_values
              equalities = equalities.grep(Arel::Nodes::Equality).find_all { |node|
                node.left.relation.name == translations_table_name
    Severity: Minor
    Found in lib/globalize/active_record/translated_attributes_query.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 changes has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

          def changes(locale)
            stash[locale].keys.inject({}) do |hash, name|
              next hash unless dirty[name].is_a?(Hash)
              next hash unless dirty[name].key?(locale)
    
    
    Severity: Minor
    Found in lib/globalize/active_record/adapter_dirty.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 validate_each has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def validate_each(record, attribute, value)
            klass = record.class
            if klass.translates? && klass.translated?(attribute)
              finder_class = klass.translation_class
              finder_table = finder_class.arel_table
    Severity: Minor
    Found in lib/patches/active_record/rails5/uniqueness_validator.rb - About 1 hr to fix

      Method validate_each has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def validate_each(record, attribute, value)
              klass = record.class
              if klass.translates? && klass.translated?(attribute)
                finder_class = klass.translation_class
                relation = build_relation(finder_class, attribute, value).where(locale: Globalize.locale)
      Severity: Minor
      Found in lib/patches/active_record/rails6_1/uniqueness_validator.rb - About 1 hr to fix

        Method validate_each has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def validate_each(record, attribute, value)
                klass = record.class
                if klass.translates? && klass.translated?(attribute)
                  finder_class = klass.translation_class
                  relation = build_relation(finder_class, attribute, value).where(locale: Globalize.locale)
        Severity: Minor
        Found in lib/patches/active_record/rails5_1/uniqueness_validator.rb - About 1 hr to fix

          Method validate_each has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def validate_each(record, attribute, value)
                klass = record.class
                if klass.translates? && klass.translated?(attribute)
                  finder_class = klass.translation_class
                  table = finder_class.arel_table
          Severity: Minor
          Found in lib/patches/active_record/rails4/uniqueness_validator.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 validate_each has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def validate_each(record, attribute, value)
                klass = record.class
                if klass.translates? && klass.translated?(attribute)
                  finder_class = klass.translation_class
                  table = finder_class.arel_table
          Severity: Minor
          Found in lib/patches/active_record/rails4/uniqueness_validator.rb - About 1 hr to fix

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

                  def save_translations!
                    stash.each do |locale, attrs|
                      next if attrs.empty?
            
                      translation = record.translations_by_locale[locale] ||
            Severity: Minor
            Found in lib/globalize/active_record/adapter.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 check_columns! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def check_columns!(attr_names)
                    # If tables do not exist or Rails version is greater than 5, do not warn about conflicting columns
                    return unless Globalize.rails_42? && table_exists? && translation_class.table_exists?
                    if (overlap = attr_names.map(&:to_s) & column_names).present?
                      ActiveSupport::Deprecation.warn(
            Severity: Minor
            Found in lib/globalize/active_record/act_macro.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 write has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def write locale, name, value
                    # Dirty tracking, paraphrased from
                    # ActiveRecord::AttributeMethods::Dirty#write_attribute.
                    name = name.to_s
                    store_old_value name, locale
            Severity: Minor
            Found in lib/globalize/active_record/adapter_dirty.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 saved_changes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                    def saved_changes
                      super.tap do |changes|
                        translation = translation_for(::Globalize.locale, false)
                        if translation
                          translation_changes = translation.saved_changes.select { |name| translated?(name) }
            Severity: Minor
            Found in lib/globalize/active_record/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 fetch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def fetch(locale, name)
                    record.globalize_fallbacks(locale).each do |fallback|
                      value = stash.contains?(fallback, name) ? fetch_stash(fallback, name) : fetch_attribute(fallback, name)
            
                      unless fallbacks_for?(value)
            Severity: Minor
            Found in lib/globalize/active_record/adapter.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

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

                  def parse_translated_order(opts)
                    case opts
                    when Hash
                      # Do not process nothing unless there is at least a translated column
                      # so that the `order` statement will be processed by the original
            Severity: Minor
            Found in lib/globalize/active_record/translated_attributes_query.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

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

                  def parse_translated_columns(columns)
                    if columns.is_a?(Array) && (columns.flatten & translated_attribute_names).present?
                      columns.flatten.map { |column| translated_column?(column) ? translated_column_name(column) : column }
                    end
                  end
            Severity: Minor
            Found in lib/globalize/active_record/translated_attributes_query.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