discourse/discourse

View on GitHub
lib/excerpt_parser.rb

Summary

Maintainability
D
2 days
Test Coverage

Method start_element has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

  def start_element(name, attributes = [])
    case name
    when "img"
      attributes = Hash[*attributes.flatten]

Severity: Minor
Found in lib/excerpt_parser.rb - About 6 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 characters has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

  def characters(string, truncate: true, count_it: true, encode: true, before_string: nil, after_string: nil)
    return if @in_quote

    # we call length on this so might as well ensure we have a string
    string = string.to_s
Severity: Minor
Found in lib/excerpt_parser.rb - About 2 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 start_element has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def start_element(name, attributes = [])
    case name
    when "img"
      attributes = Hash[*attributes.flatten]

Severity: Major
Found in lib/excerpt_parser.rb - About 2 hrs to fix

    Method end_element has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      def end_element(name)
        case name
        when "a"
          unless @strip_links
            characters("</a>", truncate: false, count_it: false, encode: false)
    Severity: Minor
    Found in lib/excerpt_parser.rb - About 2 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 end_element has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def end_element(name)
        case name
        when "a"
          unless @strip_links
            characters("</a>", truncate: false, count_it: false, encode: false)
    Severity: Minor
    Found in lib/excerpt_parser.rb - About 1 hr to fix

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

        def self.get_excerpt(html, length, options)
          html ||= ''
          length = html.length if html.include?('excerpt') && SPAN_REGEX === html
          me = self.new(length, options)
          parser = Nokogiri::HTML::SAX::Parser.new(me)
      Severity: Minor
      Found in lib/excerpt_parser.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