shioyama/mobility

View on GitHub

Showing 7 of 46 total issues

Method included has a Cognitive Complexity of 16 (exceeds 6 allowed). Consider refactoring.
Open

      def self.included(base)
        base.class_eval do
          plugin :validation_helpers

          # Paraphased from sequel_polymorphic gem
Severity: Minor
Found in lib/mobility/sequel/translation.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 15 (exceeds 6 allowed). Consider refactoring.
Open

      def validate_each(record, attribute, value)
        klass = record.class

        if ([*options[:scope]] + [attribute]).any? { |name| klass.mobility_attribute?(name) }
          return unless value.present?
Severity: Minor
Found in lib/mobility/active_record/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 prepare_for_invocation has a Cognitive Complexity of 13 (exceeds 6 allowed). Consider refactoring.
Open

    def self.prepare_for_invocation(name, value)
      if name == :backend
        if SUPPORTED_BACKENDS.include?(value)
          require_relative "./backend_generators/#{value}_backend"
          Mobility::BackendGenerators.const_get("#{value}_backend".camelcase.freeze)
Severity: Minor
Found in lib/rails/generators/mobility/translations_generator.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 define_read has a Cognitive Complexity of 9 (exceeds 6 allowed). Consider refactoring.
Open

        def define_read(fallbacks)
          define_method :read do |locale, fallback: true, **options|
            return super(locale, options) if !fallback || options[:locale]

            locales = fallback == true ? fallbacks[locale] : [locale, *fallback]
Severity: Minor
Found in lib/mobility/plugins/fallbacks.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

Method serializer_for has a Cognitive Complexity of 9 (exceeds 6 allowed). Consider refactoring.
Open

        def serializer_for(format)
          lambda do |obj|
            return if obj.nil?
            if obj.is_a? ::Hash
              obj = obj.inject({}) do |translations, (locale, value)|
Severity: Minor
Found in lib/mobility/backends/serialized.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

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

      def save_translations
        cache.each_value do |translation|
          next unless present?(translation.value)
          translation.id ? translation.save : model.send("add_#{singularize(association_name)}", translation)
        end
Severity: Minor
Found in lib/mobility/backends/sequel/key_value.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 configure has a Cognitive Complexity of 7 (exceeds 6 allowed). Consider refactoring.
Open

        def configure(options)
          raise CacheRequired, "Cache required for Sequel::Table backend" if options[:cache] == false
          table_name = Util.singularize(options[:model_class].table_name)
          options[:table_name]  ||= :"#{table_name}_translations"
          options[:foreign_key] ||= Util.foreign_key(Util.camelize(table_name.downcase))
Severity: Minor
Found in lib/mobility/backends/sequel/table.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