weby-lv/weeler

View on GitHub

Showing 16 of 16 total issues

Method generate_seo has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    def generate_seo
      self.seo = Weeler::Seo.create if self.seo.blank?

      I18n.available_locales.each do |locale|
        Globalize.with_locale(locale) do
Severity: Minor
Found in app/models/concerns/weeler/seoable.rb - About 3 hrs 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 lookup_in_database has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

        def lookup_in_database locale, key, scope = [], options = {}
          result = Translation.locale(locale).lookup(key).load

          if result.nil? || (::Weeler.empty_translation_acts_like_missing && result.blank?)
            if ::Weeler.create_missing_translations
Severity: Minor
Found in lib/i18n/backend/weeler.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 load_collection has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

          def load_collection
            return @load_collection if @load_collection.present?
            if model
              if collection
                @load_collection = collection
Severity: Minor
Found in lib/weeler/action_controller/acts/restful.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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    def update
      params[:translations].each do |translation|
        id, value = translation.first, translation.last
        translation = I18n::Backend::Weeler::Translation.find(id)
        translation.value = value
Severity: Minor
Found in app/controllers/weeler/static_sections_controller.rb and 1 other location - About 1 hr to fix
app/controllers/weeler/seo_items_controller.rb on lines 13..22

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

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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    def update
      params[:translations].each do |translation|
        id, value = translation.first, translation.last
        translation = I18n::Backend::Weeler::Translation.find(id)
        translation.value = value
Severity: Minor
Found in app/controllers/weeler/seo_items_controller.rb and 1 other location - About 1 hr to fix
app/controllers/weeler/static_sections_controller.rb on lines 8..16

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

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

Method build_main_menu has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  def self.build_main_menu
    home_menu_item = {name: "Home", weeler_path: ""}
    content_menu_item = {name: "Content", weeler_path: "content"}
    administration_menu_item = {name: "Administration", weeler_path: "administration"}
    configuration_menu_item = {name: "Configuration", weeler_path: "configuration"}
Severity: Minor
Found in lib/weeler.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 lookup_in_cache has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

        def lookup_in_cache(locale, key, scope = [], options = {})
          # reload cache if cache timestamp differs from last translations update
          reload_cache if ((!ActiveRecord::Base.connection.data_source_exists?('settings')) || i18n_cache.read('UPDATED_AT') != Setting.i18n_updated_at)

          return nil if i18n_cache.read([:missing, [locale, key]])
Severity: Minor
Found in lib/i18n/backend/weeler.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 locales_from_xlsx_sheet_row has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

          def locales_from_xlsx_sheet_row(row)
            locales = []
            row.each_with_index do |cell, i|
              next unless i.positive?

Severity: Minor
Found in lib/i18n/backend/weeler/importer.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 acquire has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def self.acquire(name)
          already_acquired = definitely_acquired?(name)

          if already_acquired
            yield
Severity: Minor
Found in lib/i18n/backend/weeler/lock.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 store_translation_from_xlsx_cell has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

          def store_translation_from_xlsx_cell(locale_translations, locale, key, cell)
            value = cell.nil? ? '' : cell

            return if locale.blank? || key.blank?

Severity: Minor
Found in lib/i18n/backend/weeler/importer.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 copy_files has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def copy_files subdir, dest_dir
        raise ArgumEnterror unless subdir.is_a? String
        raise ArgumEnterror unless dest_dir.is_a? String
        raise ArgumetnError if subdir.blank?
        raise ArgumetnError if dest_dir.blank?
Severity: Minor
Found in lib/generators/weeler/install_generator.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 get_file_list has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def get_file_list subdir
        raise ArgumentError unless subdir.is_a? String
        raise ArgumetnError if subdir.blank?
        dir = get_current_dir
        search_path = [dir, 'templates', subdir].join('/') + '/'
Severity: Minor
Found in lib/generators/weeler/install_generator.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 acts_as_restful has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

          def acts_as_restful(active_record_model, options = {})
            before_action(:load_record, only: [:show, :edit, :update, :destroy, :remove_image])

            include InstanceMethodsOnActivation
            helper_method :item_humanized_name
Severity: Minor
Found in lib/weeler/action_controller/acts/restful.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 items_params has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

          def items_params
            if permited_params.is_a? Proc
              permited_params.call(params)
            elsif permited_params.blank?
              warning_suggestion = params[parameterized_name.to_sym].is_a?(Hash) ? params[parameterized_name.to_sym].keys.map{ |k| k.to_sym } : "permit_params:"
Severity: Minor
Found in lib/weeler/action_controller/acts/restful.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 store_translations_from_xlsx_row has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

          def store_translations_from_xlsx_row(tranlsations_by_locales, row, locales)
            locale = nil
            key = nil

            row.each_with_index do |cell, i|
Severity: Minor
Found in lib/i18n/backend/weeler/importer.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 reload_cache has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def reload_cache
          i18n_cache.clear

          Translation.all.each do |translation|
            # Load in cache unless value is nil or it is blank and empty
Severity: Minor
Found in lib/i18n/backend/weeler.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