discourse/discourse

View on GitHub
plugins/poll/plugin.rb

Summary

Maintainability
D
2 days
Test Coverage

File plugin.rb has 387 lines of code (exceeds 250 allowed). Consider refactoring.
Open

register_asset "stylesheets/common/poll.scss"
register_asset "stylesheets/common/poll-ui-builder.scss"
register_asset "stylesheets/desktop/poll.scss", :desktop
register_asset "stylesheets/mobile/poll.scss", :mobile

Severity: Minor
Found in plugins/poll/plugin.rb - About 5 hrs to fix

    Method toggle_status has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

          def toggle_status(post_id, poll_name, status, user, raise_errors = true)
            Poll.transaction do
              post = Post.find_by(id: post_id)
    
              # post must not be deleted
    Severity: Minor
    Found in plugins/poll/plugin.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 vote has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

          def vote(post_id, poll_name, options, user)
            Poll.transaction do
              post = Post.find_by(id: post_id)
    
              # post must not be deleted
    Severity: Minor
    Found in plugins/poll/plugin.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 serialized_voters has 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def serialized_voters(poll, opts = {})
            limit = (opts["limit"] || 25).to_i
            limit = 0  if limit < 0
            limit = 50 if limit > 50
    
    
    Severity: Major
    Found in plugins/poll/plugin.rb - About 2 hrs to fix

      Method serialized_voters has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def serialized_voters(poll, opts = {})
              limit = (opts["limit"] || 25).to_i
              limit = 0  if limit < 0
              limit = 50 if limit > 50
      
      
      Severity: Minor
      Found in plugins/poll/plugin.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 vote has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def vote(post_id, poll_name, options, user)
              Poll.transaction do
                post = Post.find_by(id: post_id)
      
                # post must not be deleted
      Severity: Minor
      Found in plugins/poll/plugin.rb - About 1 hr to fix

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

              def toggle_status(post_id, poll_name, status, user, raise_errors = true)
                Poll.transaction do
                  post = Post.find_by(id: post_id)
        
                  # post must not be deleted
        Severity: Minor
        Found in plugins/poll/plugin.rb - About 1 hr to fix

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

                def toggle_status(post_id, poll_name, status, user, raise_errors = true)
          Severity: Minor
          Found in plugins/poll/plugin.rb - About 35 mins to fix

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

                  def create!(post_id, poll)
                    close_at = begin
                      Time.zone.parse(poll["close"] || '')
                    rescue ArgumentError
                    end
            Severity: Minor
            Found in plugins/poll/plugin.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

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

                  def voters(post_id, poll_name, user, opts = {})
                    post = Post.find_by(id: post_id)
                    raise Discourse::InvalidParameters.new("post_id is invalid") unless post
            
                    poll = Poll.find_by(post_id: post_id, name: poll_name)
            Severity: Minor
            Found in plugins/poll/plugin.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

            There are no issues that match your filters.

            Category
            Status