lml/commontator

View on GitHub

Showing 16 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

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                def unsubscribe
                  security_transgression_unless @commontator_thread.can_subscribe?(@commontator_user)
              
                  @commontator_thread.errors.add(:base, t('commontator.subscription.errors.not_subscribed')) \
                    unless @commontator_thread.unsubscribe(@commontator_user)
              Severity: Minor
              Found in app/controllers/commontator/subscriptions_controller.rb and 3 other locations - About 25 mins to fix
              app/controllers/commontator/comments_controller.rb on lines 104..112
              app/controllers/commontator/comments_controller.rb on lines 117..125
              app/controllers/commontator/subscriptions_controller.rb on lines 5..13

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 30.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                def undelete
                  security_transgression_unless @comment.can_be_deleted_by?(@commontator_user)
              
                  @comment.errors.add(:base, t('commontator.comment.errors.not_deleted')) \
                    unless @comment.undelete_by(@commontator_user)
              Severity: Minor
              Found in app/controllers/commontator/comments_controller.rb and 3 other locations - About 25 mins to fix
              app/controllers/commontator/comments_controller.rb on lines 104..112
              app/controllers/commontator/subscriptions_controller.rb on lines 5..13
              app/controllers/commontator/subscriptions_controller.rb on lines 19..27

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 30.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              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

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                def subscribe
                  security_transgression_unless @commontator_thread.can_subscribe?(@commontator_user)
              
                  @commontator_thread.errors.add(:base, t('commontator.subscription.errors.already_subscribed')) \
                    unless @commontator_thread.subscribe(@commontator_user)
              Severity: Minor
              Found in app/controllers/commontator/subscriptions_controller.rb and 3 other locations - About 25 mins to fix
              app/controllers/commontator/comments_controller.rb on lines 104..112
              app/controllers/commontator/comments_controller.rb on lines 117..125
              app/controllers/commontator/subscriptions_controller.rb on lines 19..27

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 30.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                def delete
                  security_transgression_unless @comment.can_be_deleted_by?(@commontator_user)
              
                  @comment.errors.add(:base, t('commontator.comment.errors.already_deleted')) \
                    unless @comment.delete_by(@commontator_user)
              Severity: Minor
              Found in app/controllers/commontator/comments_controller.rb and 3 other locations - About 25 mins to fix
              app/controllers/commontator/comments_controller.rb on lines 117..125
              app/controllers/commontator/subscriptions_controller.rb on lines 5..13
              app/controllers/commontator/subscriptions_controller.rb on lines 19..27

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 30.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Severity
              Category
              Status
              Source
              Language