discourse/discourse

View on GitHub
lib/cooked_post_processor.rb

Summary

Maintainability
F
5 days
Test Coverage

Method post_process_oneboxes has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
Open

  def post_process_oneboxes
    limit = SiteSetting.max_oneboxes_per_post
    oneboxes = {}
    inlineOneboxes = {}

Severity: Minor
Found in lib/cooked_post_processor.rb - About 1 day 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

File cooked_post_processor.rb has 544 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_dependency 'url_helper'
require_dependency 'pretty_text'
require_dependency 'quote_comparer'

class CookedPostProcessor
Severity: Major
Found in lib/cooked_post_processor.rb - About 1 day to fix

    Class CookedPostProcessor has 46 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class CookedPostProcessor
      INLINE_ONEBOX_LOADING_CSS_CLASS = "inline-onebox-loading"
      INLINE_ONEBOX_CSS_CLASS = "inline-onebox"
      LIGHTBOX_WRAPPER_CSS_CLASS = "lightbox-wrapper"
      LOADING_SIZE = 10
    Severity: Minor
    Found in lib/cooked_post_processor.rb - About 6 hrs to fix

      Method post_process_oneboxes has 84 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def post_process_oneboxes
          limit = SiteSetting.max_oneboxes_per_post
          oneboxes = {}
          inlineOneboxes = {}
      
      
      Severity: Major
      Found in lib/cooked_post_processor.rb - About 3 hrs to fix

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

          def add_lightbox!(img, original_width, original_height, upload, cropped: false)
            # first, create a div to hold our lightbox
            lightbox = create_node("div", LIGHTBOX_WRAPPER_CSS_CLASS)
            img.add_next_sibling(lightbox)
            lightbox.add_child(img)
        Severity: Minor
        Found in lib/cooked_post_processor.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 get_size has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          def get_size(url)
            return @size_cache[url] if @size_cache.has_key?(url)
        
            absolute_url = url
            absolute_url = Discourse.base_url_no_prefix + absolute_url if absolute_url =~ /^\/[^\/]/
        Severity: Minor
        Found in lib/cooked_post_processor.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 convert_to_link! has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          def convert_to_link!(img)
            src = img["src"]
            return if src.blank? || is_a_hyperlink?(img) || is_svg?(img)
        
            width, height = img["width"].to_i, img["height"].to_i
        Severity: Minor
        Found in lib/cooked_post_processor.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 add_lightbox! has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def add_lightbox!(img, original_width, original_height, upload, cropped: false)
            # first, create a div to hold our lightbox
            lightbox = create_node("div", LIGHTBOX_WRAPPER_CSS_CLASS)
            img.add_next_sibling(lightbox)
            lightbox.add_child(img)
        Severity: Minor
        Found in lib/cooked_post_processor.rb - About 1 hr to fix

          Method convert_to_link! has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def convert_to_link!(img)
              src = img["src"]
              return if src.blank? || is_a_hyperlink?(img) || is_svg?(img)
          
              width, height = img["width"].to_i, img["height"].to_i
          Severity: Minor
          Found in lib/cooked_post_processor.rb - About 1 hr to fix

            Method add_large_image_placeholder! has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def add_large_image_placeholder!(img)
                url = img["src"]
            
                is_hyperlinked = is_a_hyperlink?(img)
            
            
            Severity: Minor
            Found in lib/cooked_post_processor.rb - About 1 hr to fix

              Method get_size_from_attributes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def get_size_from_attributes(img)
                  w, h = img["width"].to_i, img["height"].to_i
                  return [w, h] unless w <= 0 || h <= 0
                  # if only width or height are specified attempt to scale image
                  if w > 0 || h > 0
              Severity: Minor
              Found in lib/cooked_post_processor.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 remove_user_ids has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def remove_user_ids
                  @doc.css("a[href]").each do |a|
                    uri = begin
                      URI(a["href"])
                    rescue URI::Error
              Severity: Minor
              Found in lib/cooked_post_processor.rb - About 55 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 add_large_image_placeholder! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def add_large_image_placeholder!(img)
                  url = img["src"]
              
                  is_hyperlinked = is_a_hyperlink?(img)
              
              
              Severity: Minor
              Found in lib/cooked_post_processor.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

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

                def post_process_quotes
                  @doc.css("aside.quote").each do |q|
                    post_number = q['data-post']
                    topic_id = q['data-topic']
                    if topic_id && post_number
              Severity: Minor
              Found in lib/cooked_post_processor.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 remove_full_quote_on_direct_reply has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def remove_full_quote_on_direct_reply
                  return if !SiteSetting.remove_full_quote
                  return if @post.post_number == 1
                  return if @doc.css("aside.quote").size != 1
              
              
              Severity: Minor
              Found in lib/cooked_post_processor.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 method.
              Open

                  return if previous_text.gsub(/(\s){2,}/, '\1') != quoted_text.gsub(/(\s){2,}/, '\1')
              Severity: Major
              Found in lib/cooked_post_processor.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                    return if @post.raw.strip == quoteless_raw
                Severity: Major
                Found in lib/cooked_post_processor.rb - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status