lml/commontator

View on GitHub

Showing 12 of 16 total issues

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

  def nested_comments_for(user, comments, show_all)
    includes = [ :thread, :creator, :editor ]
    total_entries = comments.total_entries
    root_per_page = config.comments_per_page[0]
    current_page = comments.current_page.to_i
Severity: Minor
Found in app/models/commontator/thread.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

Class Thread has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

class Commontator::Thread < ActiveRecord::Base
  belongs_to :closer, polymorphic: true, optional: true
  belongs_to :commontable, polymorphic: true, optional: true, inverse_of: :commontator_thread

  has_many :comments, dependent: :destroy, inverse_of: :thread
Severity: Minor
Found in app/models/commontator/thread.rb - About 2 hrs to fix

    Method create has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

      def create
        @comment = Commontator::Comment.new(
          thread: @commontator_thread, creator: @commontator_user, body: params.dig(:comment, :body)
        )
        parent_id = params.dig(:comment, :parent_id)
    Severity: Minor
    Found in app/controllers/commontator/comments_controller.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 nested_comments_for has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def nested_comments_for(user, comments, show_all)
        includes = [ :thread, :creator, :editor ]
        total_entries = comments.total_entries
        root_per_page = config.comments_per_page[0]
        current_page = comments.current_page.to_i
    Severity: Minor
    Found in app/models/commontator/thread.rb - About 2 hrs to fix

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

        def update
          @comment.editor = @commontator_user
          @comment.body = params.dig(:comment, :body)
          security_transgression_unless @comment.can_be_edited_by?(@commontator_user)
      
      
      Severity: Minor
      Found in app/controllers/commontator/comments_controller.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

      Function initMentions has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Commontator.initMentions = function() {
          $('.commontator .field textarea:not(.mentions-added)').each(function(_index, textarea){
              $textarea = $(textarea);
              $form = $textarea.parents('form');
              threadId = $textarea.parents('.thread').attr('id').match(/[\d]+/)[0];
      Severity: Minor
      Found in app/assets/javascripts/commontator/mentions.js - About 1 hr to fix

        Method setup_variables has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def setup_variables(comment, recipients)
            @comment = comment
            @thread = @comment.thread
            @creator = @comment.creator
        
        
        Severity: Minor
        Found in app/mailers/commontator/subscriptions_mailer.rb - About 1 hr to fix

          Method can_be_deleted_by? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def can_be_deleted_by?(user)
              mod_perm = thread.config.moderator_permissions.to_sym
              return true if thread.can_be_edited_by?(user) && (mod_perm == :e || mod_perm == :d)
          
              comment_del = thread.config.comment_deletion.to_sym
          Severity: Minor
          Found in app/models/commontator/comment.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 commontator_simple_format has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def commontator_simple_format(text, html_options = {}, options = {})
              wrapper_tag = options.fetch(:wrapper_tag, :p)
          
              text = sanitize(text) if options.fetch(:sanitize, true)
              paragraphs = commontator_split_paragraphs(text)
          Severity: Minor
          Found in lib/commontator/shared_helper.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 nest_comments has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              comments, root_per_page, per_page_by_parent_id, count_by_parent_id, children_by_parent_id
          Severity: Minor
          Found in app/models/commontator/thread.rb - About 35 mins to fix

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

              def initialize(array, count, root_per_page, per_page, page = 1)
            Severity: Minor
            Found in app/models/commontator/collection.rb - About 35 mins to fix

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

                def can_be_edited_by?(user)
                  return true if thread.can_be_edited_by?(user) &&
                                 thread.config.moderator_permissions.to_sym == :e
              
                  comment_edit = thread.config.comment_editing.to_sym
              Severity: Minor
              Found in app/models/commontator/comment.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

              Severity
              Category
              Status
              Source
              Language