globalize/globalize

View on GitHub

Showing 23 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

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

                      untranslated_scopes.each do |scope_item|
                        scope_value = record.send(scope_item)
                        reflection = klass.reflect_on_association(scope_item)
                        if reflection
                          scope_value = record.send(reflection.foreign_key)
            Severity: Minor
            Found in lib/patches/active_record/rails5/uniqueness_validator.rb and 2 other locations - About 35 mins to fix
            lib/patches/active_record/rails5_1/uniqueness_validator.rb on lines 16..23
            lib/patches/active_record/rails6_1/uniqueness_validator.rb on lines 16..23

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

            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 3 locations. Consider refactoring.
            Open

                      untranslated_scopes.each do |scope_item|
                        scope_value = record.send(scope_item)
                        reflection = klass.reflect_on_association(scope_item)
                        if reflection
                          scope_value = record.send(reflection.foreign_key)
            Severity: Minor
            Found in lib/patches/active_record/rails6_1/uniqueness_validator.rb and 2 other locations - About 35 mins to fix
            lib/patches/active_record/rails5/uniqueness_validator.rb on lines 17..24
            lib/patches/active_record/rails5_1/uniqueness_validator.rb on lines 16..23

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

            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 3 locations. Consider refactoring.
            Open

                      untranslated_scopes.each do |scope_item|
                        scope_value = record.send(scope_item)
                        reflection = klass.reflect_on_association(scope_item)
                        if reflection
                          scope_value = record.send(reflection.foreign_key)
            Severity: Minor
            Found in lib/patches/active_record/rails5_1/uniqueness_validator.rb and 2 other locations - About 35 mins to fix
            lib/patches/active_record/rails5/uniqueness_validator.rb on lines 17..24
            lib/patches/active_record/rails6_1/uniqueness_validator.rb on lines 16..23

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

            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

            Severity
            Category
            Status
            Source
            Language