locomotivecms/engine

View on GitHub

Showing 169 of 169 total issues

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

          delete ':id' do
            @translation = current_site.translations.by_id_or_key(params[:id]).first

            raise ::Mongoid::Errors::DocumentNotFound.new(current_site.translations, params) if translation.nil?

Severity: Minor
Found in app/api/locomotive/api/resources/translation_resource.rb and 2 other locations - About 30 mins to fix
app/api/locomotive/api/resources/section_resource.rb on lines 82..92
app/api/locomotive/api/resources/snippet_resource.rb on lines 79..89

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

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

  class ContentEntryPolicy < ApplicationPolicy

    def index?
      site_staff?
    end
Severity: Minor
Found in app/policies/locomotive/content_entry_policy.rb and 1 other location - About 30 mins to fix
app/policies/locomotive/content_asset_policy.rb on lines 2..26

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

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

  class ContentAssetPolicy < ApplicationPolicy

    def index?
      site_staff?
    end
Severity: Minor
Found in app/policies/locomotive/content_asset_policy.rb and 1 other location - About 30 mins to fix
app/policies/locomotive/content_entry_policy.rb on lines 2..26

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

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

          delete ':id' do
            @section = current_site.sections.by_id_or_slug(params[:id]).first

            raise ::Mongoid::Errors::DocumentNotFound.new(current_site.sections, params) if section.nil?

Severity: Minor
Found in app/api/locomotive/api/resources/section_resource.rb and 2 other locations - About 30 mins to fix
app/api/locomotive/api/resources/snippet_resource.rb on lines 79..89
app/api/locomotive/api/resources/translation_resource.rb on lines 80..90

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

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

          delete ':id' do
            @snippet = current_site.snippets.by_id_or_slug(params[:id]).first

            raise ::Mongoid::Errors::DocumentNotFound.new(current_site.snippets, params) if snippet.nil?

Severity: Minor
Found in app/api/locomotive/api/resources/snippet_resource.rb and 2 other locations - About 30 mins to fix
app/api/locomotive/api/resources/section_resource.rb on lines 82..92
app/api/locomotive/api/resources/translation_resource.rb on lines 80..90

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

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

        def next_or_previous(matcher = :gt)
          # the matchers is supposed to be fine for the default direction, meaning 'asc'
          # if the direction is not ascending, we need to reverse the matcher
          matcher = matcher == :gt ? :lt : :gt if self.content_type.order_direction != 'asc'

Severity: Minor
Found in app/models/locomotive/concerns/content_entry/next_previous.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 subscribe_to_sections has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def subscribe_to_sections(sections)
      ActiveSupport::Notifications.subscribe('steam.parse.section') do |name, start, finish, id, payload|
        page, block, attributes = payload[:page], payload[:block], payload[:attributes]

        if attributes[:is_dropzone]
Severity: Minor
Found in app/services/locomotive/page_parsing_service.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 vignette_url has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def vignette_url
          if self.image?
            # In some case (like an invalid extension) the height, width can be nill
            # In that case we should directly return the url
            if self.width && self.height && self.width < 85 && self.height < 85
Severity: Minor
Found in app/models/locomotive/concerns/asset/vignette.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

Function buildSectionOptions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

const buildSectionOptions = (findSectionDefinition, sections) => {
  return compact((sections || []).map(section => {
    // unknown section type, can happen if the data are messed up (first deployment)
    if (section.type === null) return null;

Severity: Minor
Found in app/javascript/src/locomotive/editor/views/pickers/urls/main.js - 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 normalize_slug has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def normalize_slug(field)
          value = self.send(field)

          if self.slug.blank? && value.present?
            self.slug = value.clone
Severity: Minor
Found in app/models/locomotive/concerns/shared/slug.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 prepare_options_for_all has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def prepare_options_for_all(options)
      { where: prepare_where_statement(options) }.tap do |_options|
        unless options[:no_pagination]
          _options[:page]     = options[:page] || 1
          _options[:per_page] = options[:per_page] || Locomotive.config.ui[:per_page]
Severity: Minor
Found in app/services/locomotive/content_entry_service.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 filename_or_image has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def filename_or_image
      if object.persisted? && persisted_file?
        css = "current-file #{persisted_file.image? ? 'image' : ''}"
        template.content_tag :span, (image_html + filename_html).html_safe, class: css
      else
Severity: Minor
Found in app/inputs/locomotive/file_input.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 ensure_target_klass_name_security has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def ensure_target_klass_name_security
          return if !self.templatized? || self.target_klass_name.blank?

          if self.target_klass_name =~ /^Locomotive::ContentEntry([a-z0-9]+)$/
            content_type = Locomotive::ContentType.find($1)
Severity: Minor
Found in app/models/locomotive/concerns/page/templatized.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 persist_editable_elements! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def persist_editable_elements!(page, parsed)
      modified_pages, pages = [], { page._id => page } # group modifications by page

      parsed[:elements].map! do |couple|
        _page, attributes = couple
Severity: Minor
Found in app/services/locomotive/page_parsing_service.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

Function _build has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

const _build = (tree, prefix, routes) => {
  return transform(tree, (result, value, key) => {
    const path = `${prefix}${key}`;

    if (typeof(value) === 'object') {
Severity: Minor
Found in app/javascript/src/locomotive/editor/utils/routes_builder.js - 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 bulk_create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def bulk_create(list)
      list = list.values if list.is_a?(Hash)

      assets = list.map { |params| create_or_update(params) }
        
Severity: Minor
Found in app/services/locomotive/content_asset_service.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 sync_relationships_order_by_for_belongs_to_fields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def sync_relationships_order_by_for_belongs_to_fields
          current_class_name = self.klass_with_custom_fields(:entries).name

          self.entries_custom_fields.where(type: 'belongs_to').each do |field|
            target_content_type = self.class_name_to_content_type(field.class_name)
Severity: Minor
Found in app/models/locomotive/concerns/content_type/sync.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 remove! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def remove!
      record.class.uploaders.each do |_column, _|
        next if _column == column

        _mounter    = self.record.send(:_mounter, _column)
Severity: Minor
Found in lib/locomotive/carrierwave/patches.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 ensure_class_name_security has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def ensure_class_name_security(field)
          if field.class_name =~ /^Locomotive::ContentEntry([a-z0-9]+)$/
            # if the content type does not exist (anymore), bypass the security checking
            content_type = Locomotive::ContentType.find($1) rescue return

Severity: Minor
Found in app/models/locomotive/concerns/content_type/class_helpers.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

Function findBetterImageAndText has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export function findBetterImageAndText(sectionContent, definition) {
  var image = null, text = null;

  if (!definition.keep_icon) {
    image = findFirstSettingValueOf('image_picker', sectionContent, definition);
Severity: Minor
Found in app/javascript/src/locomotive/editor/services/sections_service.js - 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