discourse/discourse

View on GitHub
lib/post_revisor.rb

Summary

Maintainability
F
3 days
Test Coverage

File post_revisor.rb has 473 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "edit_rate_limiter"
require 'post_locker'

class PostRevisor

Severity: Minor
Found in lib/post_revisor.rb - About 7 hrs to fix

    Class PostRevisor has 50 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class PostRevisor
    
      # Helps us track changes to a topic.
      #
      # It's passed to `track_topic_fields` callbacks so they can record if they
    Severity: Minor
    Found in lib/post_revisor.rb - About 7 hrs to fix

      Method update_post has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

        def update_post
          if @fields.has_key?("user_id") && @fields["user_id"] != @post.user_id && @post.user_id != nil
            prev_owner = User.find(@post.user_id)
            new_owner = User.find(@fields["user_id"])
      
      
      Severity: Minor
      Found in lib/post_revisor.rb - About 4 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 revise! has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def revise!(editor, fields, opts = {})
          @editor = editor
          @fields = fields.with_indifferent_access
          @opts = opts
      
      
      Severity: Minor
      Found in lib/post_revisor.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 revise! has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def revise!(editor, fields, opts = {})
          @editor = editor
          @fields = fields.with_indifferent_access
          @opts = opts
      
      
      Severity: Major
      Found in lib/post_revisor.rb - About 2 hrs to fix

        Method update_post has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def update_post
            if @fields.has_key?("user_id") && @fields["user_id"] != @post.user_id && @post.user_id != nil
              prev_owner = User.find(@post.user_id)
              new_owner = User.find(@fields["user_id"])
        
        
        Severity: Minor
        Found in lib/post_revisor.rb - About 2 hrs to fix

          Method update_revision has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

            def update_revision
              return unless revision = PostRevision.find_by(post_id: @post.id, number: @post.version)
              revision.user_id = @post.last_editor_id
              modifications = post_changes.merge(@topic_changes.diff)
          
          
          Severity: Minor
          Found in lib/post_revisor.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 ninja_edit? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def ninja_edit?
              return false if (@revised_at - @last_version_at) > SiteSetting.editing_grace_period.to_i
              return false if @post.reviewable_flag.present?
          
              if new_raw = @fields[:raw]
          Severity: Minor
          Found in lib/post_revisor.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

          Consider simplifying this complex logical expression.
          Open

              if (
                SiteSetting.staff_edit_locks_post? &&
                !@post.wiki? &&
                @fields.has_key?('raw') &&
                @editor.staff? &&
          Severity: Major
          Found in lib/post_revisor.rb - About 40 mins to fix

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

              def update_category_description
                return unless category = Category.find_by(topic_id: @topic.id)
            
                doc = Nokogiri::HTML.fragment(@post.cooked)
                doc.css("img").remove
            Severity: Minor
            Found in lib/post_revisor.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 update_topic has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def update_topic
                Topic.transaction do
                  PostRevisor.tracked_topic_fields.each do |f, cb|
                    if !@topic_changes.errored? && @fields.has_key?(f)
                      cb.call(@topic_changes, @fields[f])
            Severity: Minor
            Found in lib/post_revisor.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

            There are no issues that match your filters.

            Category
            Status