locomotivecms/engine

View on GitHub

Showing 91 of 169 total issues

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

    def bubble_fields_errors_up
      return if self.errors[:entries_custom_fields].empty?

      self.entries_custom_fields.each do |field|
        next if field.errors.blank?
Severity: Minor
Found in app/models/locomotive/content_type.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 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 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 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 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 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 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 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 encoded? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def encoded?(hash)
              return false if hash.empty?
              if hash.keys.size > 1
                keys = hash.keys.map{|i| i.to_i if i.respond_to?(:to_i)}.sort
                keys == hash.keys.size.times.to_a
    Severity: Minor
    Found in app/api/locomotive/api/middlewares/params_decoder_middleware.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 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 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

    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

    Method handle_no_account_or_site has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def handle_no_account_or_site(env, request)
            if Locomotive::Account.count == 0
              redirect_to((Locomotive.config.enable_registration ? sign_up_path : sign_in_path))
            elsif default_host?(request)
              redirect_to(sign_in_path)
    Severity: Minor
    Found in lib/locomotive/middlewares/site.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

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

      signalExpandShowModal() {
        const { onExpandEvent, currentState: { link, selectionText } } = this.props;
        const { linkTargetOption } = this.state;
        onExpandEvent();
        this.setState({
    Severity: Minor
    Found in app/javascript/src/locomotive/editor/components/draft/link.jsx - 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

    Severity
    Category
    Status
    Source
    Language