aq1018/dm-is-slug

View on GitHub

Showing 5 of 5 total issues

Method unique_slug has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

        def unique_slug
          max_length = self.class.send(:get_slug_length)
          base_slug = ::DataMapper::Is::Slug.escape(slug_source_value)[0, max_length]
          # Assuming that 5 digits is more than enought
          index_length = 5
Severity: Minor
Found in lib/dm-is-slug/is/slug.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 unique_slug has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def unique_slug
          max_length = self.class.send(:get_slug_length)
          base_slug = ::DataMapper::Is::Slug.escape(slug_source_value)[0, max_length]
          # Assuming that 5 digits is more than enought
          index_length = 5
Severity: Minor
Found in lib/dm-is-slug/is/slug.rb - About 1 hr to fix

    Method is_slug has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

          def is_slug(options)
            if options.key?(:size)
              warn "Slug with :size option is deprecated, use :length instead"
              options[:length] = options.delete(:size)
            end
    Severity: Minor
    Found in lib/dm-is-slug/is/slug.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 is_slug has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def is_slug(options)
            if options.key?(:size)
              warn "Slug with :size option is deprecated, use :length instead"
              options[:length] = options.delete(:size)
            end
    Severity: Minor
    Found in lib/dm-is-slug/is/slug.rb - About 1 hr to fix

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

              def generate_slug
                return unless self.class.respond_to?(:slug_options) && self.class.slug_options
                raise InvalidSlugSourceError, 'Invalid slug source.' unless slug_source_property || self.respond_to?(slug_source)
                return unless stale_slug?
                attribute_set slug_field, unique_slug
      Severity: Minor
      Found in lib/dm-is-slug/is/slug.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

      Severity
      Category
      Status
      Source
      Language