piotrmurach/strings-truncation

View on GitHub
lib/strings/truncation.rb

Summary

Maintainability
C
1 day
Test Coverage

Method slice has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

    def slice(text, from, length, omission_width: 0, separator: nil)
      scanner = StringScanner.new(text)
      length_with_omission = length + omission_width
      current_length = 0
      start_position = 0
Severity: Minor
Found in lib/strings/truncation.rb - About 7 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 slice has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def slice(text, from, length, omission_width: 0, separator: nil)
      scanner = StringScanner.new(text)
      length_with_omission = length + omission_width
      current_length = 0
      start_position = 0
Severity: Major
Found in lib/strings/truncation.rb - About 2 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                if separator
                  word << char unless word_break
                else
                  words << char
                  visible_char = true
    Severity: Major
    Found in lib/strings/truncation.rb - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                  if word_break
                    word_break = false
                    current_length = 0
                    next
                  end
      Severity: Major
      Found in lib/strings/truncation.rb - About 45 mins to fix

        Method truncate_from has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def truncate_from(from, text, length, omission, separator)
        Severity: Minor
        Found in lib/strings/truncation.rb - About 35 mins to fix

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

              def truncate(text, truncate_at = configuration.length, length: nil,
                           position: configuration.position,
                           separator: configuration.separator,
                           omission: configuration.omission)
                truncate_at = length if length
          Severity: Minor
          Found in lib/strings/truncation.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

          There are no issues that match your filters.

          Category
          Status