dblock/slack-gamebot

View on GitHub

Showing 58 of 126 total issues

Avoid deeply nested control flow statements.
Open

              current = :scores if opponents.count == teammates.count
Severity: Major
Found in slack-gamebot/commands/draw.rb - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                    challenge.draw_scores? ? "Recorded #{Score.scores_to_string(challenge.draw_scores)}." : nil
    Severity: Major
    Found in slack-gamebot/commands/draw.rb - About 45 mins to fix

      Consider simplifying this complex logical expression.
      Open

        if (code && game && (game == 'pong' || game == 'chess' || game == 'pool' || game == 'tic-tac-toe')) {
          PlayPlay.register();
          PlayPlay.message('Working, please wait ...');
          $.ajax({
            type: "POST",
      Severity: Major
      Found in public/js/register.js - About 40 mins to fix

        Consider simplifying this complex logical expression.
        Open

          if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] > 2)) {
            throw new Error('Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3')
          }
        Severity: Major
        Found in public/js/bootstrap.js - About 40 mins to fix

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

                  def unset(client, data, user, k, v)
          Severity: Minor
          Found in slack-gamebot/commands/set.rb - About 35 mins to fix

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

              def self.new_from_teammates_and_opponents(client, channel, challenger, names, separator = 'with')
            Severity: Minor
            Found in slack-gamebot/models/challenge.rb - About 35 mins to fix

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

                      def set(client, data, user, k, v)
              Severity: Minor
              Found in slack-gamebot/commands/set.rb - About 35 mins to fix

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

                  def self.create_from_teammates_and_opponents!(client, channel, challenger, names, separator = 'with')
                Severity: Minor
                Found in slack-gamebot/models/challenge.rb - About 35 mins to fix

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

                          def set_aliases(client, data, user, v)
                            raise SlackGamebot::Error, "You're not a captain, sorry." unless v.nil? || user.captain?
                  
                            unless v.nil?
                              client.owner.update_attributes!(aliases: v.split(/[\s,;]+/))
                  Severity: Minor
                  Found in slack-gamebot/commands/set.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 score_verb has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def score_verb
                      if tied?
                        'tied with'
                      elsif !scores
                        'defeated'
                  Severity: Minor
                  Found in slack-gamebot/models/match.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 draw! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def draw!(player, scores = nil)
                      raise SlackGamebot::Error, 'Challenge must first be accepted.' if state == ChallengeState::PROPOSED
                      raise SlackGamebot::Error, "Challenge has already been #{state}." unless state == ChallengeState::ACCEPTED || state == ChallengeState::DRAWN
                      raise SlackGamebot::Error, "Already recorded a draw from #{player.user_name}." if draw.include?(player)
                  
                  
                  Severity: Minor
                  Found in slack-gamebot/models/challenge.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 function.
                  Open

                      if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom'
                  Severity: Major
                  Found in public/js/bootstrap.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return false
                    Severity: Major
                    Found in public/js/bootstrap.js - About 30 mins to fix

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

                        def to_s
                          [
                            "#{label}: #{winners ? winners.map(&:to_s).and : 'n/a'}",
                            "#{team.matches.count} match#{team.matches.count == 1 ? '' : 'es'}",
                            "#{players.count} player#{players.count == 1 ? '' : 's'}"
                      Severity: Minor
                      Found in slack-gamebot/models/season.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 check_active_subscriptions_without_teams! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def check_active_subscriptions_without_teams!
                            Stripe::Subscription.all(plan: 'slack-playplay-yearly').each do |subscription|
                              next if subscription.cancel_at_period_end
                              next if Team.where(stripe_customer_id: subscription.customer).exists?
                      
                      
                      Severity: Minor
                      Found in slack-gamebot/app.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 activated! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def activated!
                          return unless active? && activated_user_id && bot_user_id
                          return unless active_changed? || activated_user_id_changed?
                      
                          inform_activated!
                      Severity: Minor
                      Found in slack-gamebot/models/team.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 sort has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def sort(coll, options = {})
                              sort_order = sort_order(options)
                              unless sort_order.empty?
                                if coll.respond_to?(:asc) && coll.respond_to?(:desc)
                                  sort_order.each do |s|
                      Severity: Minor
                      Found in slack-gamebot/api/helpers/sort_helpers.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 ping_if_active! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def ping_if_active!
                          return unless active?
                      
                          ping!
                        rescue Slack::Web::Api::Errors::SlackError => e
                      Severity: Minor
                      Found in slack-gamebot/models/team.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