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 547 lines of code (exceeds 250 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: Major
Found in lib/cooked_post_processor.rb - About 1 day to fix

    Class CookedPostProcessor has 47 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 get_size has a Cognitive Complexity of 19 (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 17 (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 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 34 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 optimize_image! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

            def optimize_image!(img, upload, cropped: false)
              w, h = img["width"].to_i, img["height"].to_i
          
              # note: optimize_urls cooks the src and data-small-upload further after this
              thumbnail = upload.thumbnail(w, h)
          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_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 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.xpath("aside[contains(@class, '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

            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

            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

              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

                There are no issues that match your filters.

                Category
                Status