Locale/localeapp

View on GitHub

Showing 11 of 17 total issues

Method translate has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

  def translate(key, options = {})
    options = options.dup
    remaining_defaults = Array(options.delete(:default))
    options[:default] = remaining_defaults.shift if remaining_defaults.first.kind_of? String

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 remove_child_keys! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def remove_child_keys!(sub_hash, keys)
      return if sub_hash.nil?
      current_key = keys.shift
      if keys.empty?
        # delete key except if key is now used as a namespace for a child_hash
Severity: Minor
Found in lib/localeapp/updater.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 make_call has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def make_call(method, url)
      begin
        @connection_attempts += 1
        Localeapp.debug("ATTEMPT #{@connection_attempts}")
        headers = { :x_localeapp_gem_version => Localeapp::VERSION }.merge(options[:headers] || {})
Severity: Minor
Found in lib/localeapp/api_caller.rb - About 1 hr to fix

    Method default has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def default(locale, object, subject, options = {})
        result = default_without_handler(locale, object, subject, options)
    
        original_object = object
        object ||= Thread.current[:i18n_default_object]
    Severity: Minor
    Found in lib/localeapp/default_value_handler.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 update has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def update(data)
          data['locales'].each do |short_code|
            filename = File.join(Localeapp.configuration.translation_data_directory, "#{short_code}.yml")
    
            if File.exist?(filename)
    Severity: Minor
    Found in lib/localeapp/updater.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 translate has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def translate(key, options = {})
        options = options.dup
        remaining_defaults = Array(options.delete(:default))
        options[:default] = remaining_defaults.shift if remaining_defaults.first.kind_of? String
    
    

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

          def call(obj)
            method, url = send("#{endpoint}_endpoint", options[:url_options] || {})
            Localeapp.debug("API CALL: #{method} #{url}")
            success = false
            while connection_attempts < max_connection_attempts
      Severity: Minor
      Found in lib/localeapp/api_caller.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 flatten_translations has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def flatten_translations(locale, data, escape, subtree)
              hash = {}
              flatten_keys(data, escape) do |key, value|
                if value.is_a?(Hash)
                  hash[key] = value if subtree
      Severity: Minor
      Found in lib/localeapp/rails/flatten.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 handle_translation_updates has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def handle_translation_updates
              raise Localeapp::MissingApiKey unless ::Localeapp.configuration.has_api_key?
              unless ::Localeapp.configuration.polling_disabled?
                ::Localeapp.log_with_time 'Handling translation updates'
                if ::Localeapp.poller.needs_polling?
      Severity: Minor
      Found in lib/localeapp/rails/controller.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 make_call has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def make_call(method, url)
            begin
              @connection_attempts += 1
              Localeapp.debug("ATTEMPT #{@connection_attempts}")
              headers = { :x_localeapp_gem_version => Localeapp::VERSION }.merge(options[:headers] || {})
      Severity: Minor
      Found in lib/localeapp/api_caller.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 to_send has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def to_send
            data = []
            # need the sort to make specs work under 1.8
            @translations.sort { |a, b| a.to_s <=> b.to_s }.each do |locale, records|
              records.each do |key, record|
      Severity: Minor
      Found in lib/localeapp/missing_translations.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

      Severity
      Category
      Status
      Source
      Language