dblock/slack-gamebot

View on GitHub

Showing 126 of 126 total issues

Function applyPlacement has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  Tooltip.prototype.applyPlacement = function (offset, placement) {
    var $tip   = this.tip()
    var width  = $tip[0].offsetWidth
    var height = $tip[0].offsetHeight

Severity: Minor
Found in public/js/bootstrap.js - About 1 hr to fix

    Method find_by_slack_mention! has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.find_by_slack_mention!(client, user_name)
        team = client.owner
        slack_id = slack_mention?(user_name)
        user = if slack_id
                 team.users.where(user_id: slack_id).first
    Severity: Minor
    Found in slack-gamebot/models/user.rb - About 1 hr to fix

      Method calculated_elo has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def calculated_elo
          @calcualted_elo ||= begin
            winners_delta = []
            losers_delta = []
            winners_elo = Elo.team_elo(winners)
      Severity: Minor
      Found in slack-gamebot/models/match.rb - About 1 hr to fix

        Function show has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          Tab.prototype.show = function () {
            var $this    = this.element
            var $ul      = $this.closest('ul:not(.dropdown-menu)')
            var selector = $this.data('target')
        
        
        Severity: Minor
        Found in public/js/bootstrap.js - About 1 hr to fix

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

            Affix.prototype.checkPosition = function () {
              if (!this.$element.is(':visible')) return
          
              var height       = this.$element.height()
              var offset       = this.options.offset
          Severity: Minor
          Found in public/js/bootstrap.js - About 1 hr to fix

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

              def resign!(loser, 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
            
                winners, losers = winners_and_losers_for_resigned(loser)
            Severity: Major
            Found in slack-gamebot/models/challenge.rb and 1 other location - About 1 hr to fix
            slack-gamebot/models/challenge.rb on lines 99..105

            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 50.

            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 2 locations. Consider refactoring.
            Open

              def lose!(loser, 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
            
                winners, losers = winners_and_losers_for(loser)
            Severity: Major
            Found in slack-gamebot/models/challenge.rb and 1 other location - About 1 hr to fix
            slack-gamebot/models/challenge.rb on lines 118..124

            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 50.

            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 validate_unique_challenge has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def validate_unique_challenge
                return unless state == ChallengeState::PROPOSED || state == ChallengeState::ACCEPTED
            
                (challengers + challenged).each do |player|
                  existing_challenge = ::Challenge.find_by_user(team, channel, player)
            Severity: Minor
            Found in slack-gamebot/models/challenge.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 calculate_streaks! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def calculate_streaks!
                longest_winning_streak = 0
                longest_losing_streak = 0
                current_winning_streak = 0
                current_losing_streak = 0
            Severity: Minor
            Found in slack-gamebot/models/user.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 set_leaderboard_max has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                    def set_leaderboard_max(client, data, user, v)
                      raise SlackGamebot::Error, "You're not a captain, sorry." unless v.nil? || user.captain?
            
                      unless v.nil?
                        v = parse_int_with_inifinity(v)
            Severity: Minor
            Found in slack-gamebot/commands/set.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 rank! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.rank!(team)
                rank = 1
                players = any_of({ :wins.gt => 0 }, { :losses.gt => 0 }, :ties.gt => 0).where(team: team, registered: true).desc(:elo).desc(:wins).asc(:losses).desc(:ties)
                players.each_with_index do |player, index|
                  if player.registered?
            Severity: Minor
            Found in slack-gamebot/models/user.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 hide has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              Collapse.prototype.hide = function () {
                if (this.transitioning || !this.$element.hasClass('in')) return
            
                var startEvent = $.Event('hide.bs.collapse')
                this.$element.trigger(startEvent)
            Severity: Minor
            Found in public/js/bootstrap.js - About 1 hr to fix

              Function next has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  function next() {
                    $active
                      .removeClass('active')
                      .find('> .dropdown-menu > .active')
                        .removeClass('active')
              Severity: Minor
              Found in public/js/bootstrap.js - About 1 hr to fix

                Function cbpAnimatedHeader has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                var cbpAnimatedHeader = (function() {
                
                    var docElem = document.documentElement,
                        header = document.querySelector( '.navbar-default' ),
                        didScroll = false,
                Severity: Minor
                Found in public/js/cbpAnimatedHeader.js - About 1 hr to fix

                  Function refresh has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    ScrollSpy.prototype.refresh = function () {
                      var that          = this
                      var offsetMethod  = 'offset'
                      var offsetBase    = 0
                  
                  
                  Severity: Minor
                  Found in public/js/bootstrap.js - About 1 hr to fix

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

                        self.timeout = setTimeout(function () {
                          if (self.hoverState == 'out') self.hide()
                        }, self.options.delay.hide)
                    Severity: Major
                    Found in public/js/bootstrap.js and 1 other location - About 1 hr to fix
                    public/js/bootstrap.js on lines 1382..1384

                    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 55.

                    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 2 locations. Consider refactoring.
                    Open

                        self.timeout = setTimeout(function () {
                          if (self.hoverState == 'in') self.show()
                        }, self.options.delay.show)
                    Severity: Major
                    Found in public/js/bootstrap.js and 1 other location - About 1 hr to fix
                    public/js/bootstrap.js on lines 1416..1418

                    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 55.

                    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 validate_updated_by has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def validate_updated_by
                        case state
                        when ChallengeState::ACCEPTED
                          return if updated_by && challenged.include?(updated_by)
                    
                    
                    Severity: Minor
                    Found in slack-gamebot/models/challenge.rb - About 55 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 set_api has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                            def set_api(client, data, user, v)
                              raise SlackGamebot::Error, "You're not a captain, sorry." unless v.nil? || user.captain?
                    
                              client.owner.update_attributes!(api: v.to_b) unless v.nil?
                              message = [
                    Severity: Minor
                    Found in slack-gamebot/commands/set.rb - About 55 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 set_unbalanced has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                            def set_unbalanced(client, data, user, v)
                              raise SlackGamebot::Error, "You're not a captain, sorry." unless v.nil? || user.captain?
                    
                              client.owner.update_attributes!(unbalanced: v.to_b) unless v.nil?
                              client.say(channel: data.channel, text: "Unbalanced challenges for team #{client.owner.name} are #{client.owner.unbalanced? ? 'on!' : 'off.'}", gif: 'balance')
                    Severity: Minor
                    Found in slack-gamebot/commands/set.rb - About 55 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