locomotivecms/engine

View on GitHub

Showing 91 of 169 total issues

Method cast_metafields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def cast_metafields(namespace)
          return nil if namespace.blank? || !has_metafields?

          schema = self.metafields_schema.find { |s| s['name'] == namespace }
          values = self.metafields[namespace]
Severity: Minor
Found in app/models/locomotive/concerns/site/metafields.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 build_tree has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def build_tree
      pages, page_not_found = pages_with_minimun_attributes, nil

      [].tap do |tree|
        while page = pages.shift
Severity: Minor
Found in app/services/locomotive/page_tree_service.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 render_index has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def render_index
      if @editable_elements
        @editable_elements_by_block = parsing_service.group_and_sort_editable_elements(@editable_elements)
        @blocks = parsing_service.blocks_from_grouped_editable_elements(@editable_elements_by_block)
      end
Severity: Minor
Found in app/controllers/locomotive/editable_elements_controller.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 sanitize_attributes! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def sanitize_attributes!(attributes)
      # needed to get the custom fields
      _entry = content_type.entries.build

      # if the user deletes all the entries of a many_to_many field,
Severity: Minor
Found in app/services/locomotive/content_entry_service.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 order_by_definition has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def order_by_definition(reverse_order = false)
          direction = self.order_manually? ? 'asc' : self.order_direction || 'asc'

          if reverse_order
            direction = (direction == 'asc' ? 'desc' : 'asc')
Severity: Minor
Found in app/models/locomotive/concerns/content_type/order_by.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 update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def update(site, attributes, raise_if_not_valid = false)
      site.attributes = attributes

      new_locales = site.locales_changed? ? site.locales - site.locales_was : nil
      previous_default_locale = site.default_locale_was
Severity: Minor
Found in app/services/locomotive/site_service.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 set_raw_template has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def set_raw_template
          return unless site

          site.with_default_locale do
            if layout_id == 'parent'
Severity: Minor
Found in app/models/locomotive/concerns/page/layout.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 create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def create(email_or_account)
      _account = if email_or_account.respond_to?(:email)
        email_or_account
      else
        Locomotive::Account.find_by_email(email_or_account)
Severity: Minor
Found in app/services/locomotive/membership_service.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

Avoid too many return statements within this function.
Open

    return null;
Severity: Major
Found in app/javascript/src/locomotive/editor/hoc/with_editing_section.js - About 30 mins to fix

    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

    Severity
    Category
    Status
    Source
    Language