porkchopclub/porkchop

View on GitHub

Showing 104 of 104 total issues

Class Match has 27 methods (exceeds 20 allowed). Consider refactoring.
Open

class Match < ActiveRecord::Base
  WINNER_SQL = %{ "matches"."victor_id" }.freeze
  LOSER_SQL = <<-SQL.freeze
    CASE
    WHEN "matches"."victor_id" = "home_player_id" THEN "away_player_id"
Severity: Minor
Found in app/models/match.rb - About 3 hrs to fix

    Block has too many lines. [56/25]
    Open

    namespace :porkchop do
      desc "Pretend someone is pressing buttons on the table"
      task press_buttons: [:environment] do
        loop do
          sleep rand(3.0..5.0)
    Severity: Minor
    Found in lib/tasks/porkchop.rake by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

    class Stats::Personal
      def initialize(player)
        @player = player
      end
    
    
    Severity: Minor
    Found in app/services/stats/personal.rb - About 2 hrs to fix

      Block has too many lines. [35/25]
      Open

      json.match do
        json.id @ongoing_match.to_param
      
        json.home_score @ongoing_match.home_score
        json.home_player_name @ongoing_match.home_player.try!(:nickname) || @ongoing_match.home_player.try!(:name)

      This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

      const InactivePlayersList = (props) => {
        const { retiredPlayers, unretiredPlayers, activatePlayer } = props
      
        const retiredPlayerListItems = retiredPlayers.map((player) => {
          return (
      Severity: Minor
      Found in app/javascript/components/scoreboard/InactivePlayersList.js - About 1 hr to fix

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

          create_table "season_matches", force: :cascade do |t|
            t.integer  "match_id"
            t.integer  "season_id"
            t.datetime "created_at", null: false
            t.datetime "updated_at", null: false
        Severity: Major
        Found in db/schema.rb and 2 other locations - About 55 mins to fix
        db/schema.rb on lines 89..96
        db/schema.rb on lines 107..114

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

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

          create_table "points", force: :cascade do |t|
            t.integer  "match_id"
            t.integer  "victor_id"
            t.datetime "created_at", null: false
            t.datetime "updated_at", null: false
        Severity: Major
        Found in db/schema.rb and 2 other locations - About 55 mins to fix
        db/schema.rb on lines 98..105
        db/schema.rb on lines 107..114

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

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

          create_table "season_memberships", force: :cascade do |t|
            t.integer  "player_id"
            t.integer  "season_id"
            t.datetime "created_at", null: false
            t.datetime "updated_at", null: false
        Severity: Major
        Found in db/schema.rb and 2 other locations - About 55 mins to fix
        db/schema.rb on lines 89..96
        db/schema.rb on lines 98..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 44.

        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

        Block has too many lines. [31/25]
        Open

          task simulate_matches: [:environment] do
            require 'factory_girl_rails'
        
            Player.update_all active: true
            Match.setup!
        Severity: Minor
        Found in lib/tasks/porkchop.rake by rubocop

        This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

          def self.setup!(matchup = nil, table: Table.default)
            matchup ||= Matchmaker.choose
            return unless matchup.valid?
        
            player1, player2 = *matchup.players.sort_by(&:name)
        Severity: Minor
        Found in app/models/match.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

        Block has too many lines. [28/25]
        Open

        namespace :porkchop do
          namespace :stats do
            desc "Regenerate ELO and streaks"
            task regenerate: [:environment] do
              EloRating.delete_all
        Severity: Minor
        Found in lib/tasks/porkchop/stats.rake by rubocop

        This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

          def game_point
            return if finished?
            if highest_score >= 10 && score_differential > 0
              leader == home_player ? :home : :away
            end
        Severity: Minor
        Found in app/models/match.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 2 locations. Consider refactoring.
        Open

          def change
            create_table :season_memberships do |t|
              t.references :player, index: true
              t.references :season, index: true
        
        
        Severity: Minor
        Found in db/migrate/20150525213933_create_season_memberships.rb and 1 other location - About 25 mins to fix
        db/migrate/20150617032511_create_season_matches.rb on lines 2..11

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

          def change
            create_table :season_matches do |t|
              t.belongs_to :match, index: true
              t.belongs_to :season, index: true
        
        
        Severity: Minor
        Found in db/migrate/20150617032511_create_season_matches.rb and 1 other location - About 25 mins to fix
        db/migrate/20150525213933_create_season_memberships.rb on lines 2..11

        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

        Block has too many lines. [26/25]
        Open

          namespace :stats do
            desc "Regenerate ELO and streaks"
            task regenerate: [:environment] do
              EloRating.delete_all
              Stats::Streak.delete_all
        Severity: Minor
        Found in lib/tasks/porkchop/stats.rake by rubocop

        This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

        Avoid using touch because it skips validations.
        Open

            touch(:finalized_at) unless finalized_at
        Severity: Minor
        Found in app/models/season.rb by rubocop

        This cop checks for the use of methods which skip validations which are listed in http://guides.rubyonrails.org/active_record_validations.html#skipping-validations

        Example:

        # bad
        Article.first.decrement!(:view_count)
        DiscussionBoard.decrement_counter(:post_count, 5)
        Article.first.increment!(:view_count)
        DiscussionBoard.increment_counter(:post_count, 5)
        person.toggle :active
        product.touch
        Billing.update_all("category = 'authorized', author = 'David'")
        user.update_attribute(website: 'example.com')
        user.update_columns(last_request_at: Time.current)
        Post.update_counters 5, comment_count: -1, action_count: 1
        
        # good
        user.update_attributes(website: 'example.com')
        FileUtils.touch('file')

        Models should subclass ApplicationRecord.
        Open

        class Point < ActiveRecord::Base
        Severity: Minor
        Found in app/models/point.rb by rubocop

        This cop checks that models subclass ApplicationRecord with Rails 5.0.

        Example:

        # good class Rails5Model < ApplicationRecord # ... end

        # bad class Rails4Model < ActiveRecord::Base # ... end

        Specify an :inverse_of option.
        Open

          belongs_to :victor, class_name: "Player"
        Severity: Minor
        Found in app/models/match.rb by rubocop

        This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

        Example:

        # good
        class Blog < ApplicationRecord
          has_many :posts
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Blog < ApplicationRecord
          has_many :posts, -> { order(published_at: :desc) }
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          has_many(:posts,
            -> { order(published_at: :desc) },
            inverse_of: :blog
          )
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          with_options inverse_of: :blog do
            has_many :posts, -> { order(published_at: :desc) }
          end
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        # good
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end

        Example:

        # bad
        # However, RuboCop can not detect this pattern...
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician
          belongs_to :patient
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end
        
        # good
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician, inverse_of: :appointments
          belongs_to :patient, inverse_of: :appointments
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end

        @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

        Specify an :inverse_of option.
        Open

          belongs_to :favourite, class_name: "Player"
        Severity: Minor
        Found in app/models/betting_info.rb by rubocop

        This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

        Example:

        # good
        class Blog < ApplicationRecord
          has_many :posts
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Blog < ApplicationRecord
          has_many :posts, -> { order(published_at: :desc) }
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          has_many(:posts,
            -> { order(published_at: :desc) },
            inverse_of: :blog
          )
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end
        
        # good
        class Blog < ApplicationRecord
          with_options inverse_of: :blog do
            has_many :posts, -> { order(published_at: :desc) }
          end
        end
        
        class Post < ApplicationRecord
          belongs_to :blog
        end

        Example:

        # bad
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable
        end
        
        # good
        class Picture < ApplicationRecord
          belongs_to :imageable, polymorphic: true
        end
        
        class Employee < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end
        
        class Product < ApplicationRecord
          has_many :pictures, as: :imageable, inverse_of: :imageable
        end

        Example:

        # bad
        # However, RuboCop can not detect this pattern...
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician
          belongs_to :patient
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end
        
        # good
        class Physician < ApplicationRecord
          has_many :appointments
          has_many :patients, through: :appointments
        end
        
        class Appointment < ApplicationRecord
          belongs_to :physician, inverse_of: :appointments
          belongs_to :patient, inverse_of: :appointments
        end
        
        class Patient < ApplicationRecord
          has_many :appointments
          has_many :physicians, through: :appointments
        end

        @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

        Use safe navigation (&.) instead of checking if an object exists before calling the method.
        Open

            if ongoing_season && ongoing_season.eligible?(matchup)
        Severity: Minor
        Found in app/models/match.rb by rubocop

        This cop transforms usages of a method call safeguarded by a non nil check for the variable whose method is being called to safe navigation (&.).

        Configuration option: ConvertCodeThatCanStartToReturnNil The default for this is false. When configured to true, this will check for code in the format !foo.nil? && foo.bar. As it is written, the return of this code is limited to false and whatever the return of the method is. If this is converted to safe navigation, foo&.bar can start returning nil as well as what the method returns.

        Example:

        # bad
        foo.bar if foo
        foo.bar(param1, param2) if foo
        foo.bar { |e| e.something } if foo
        foo.bar(param) { |e| e.something } if foo
        
        foo.bar if !foo.nil?
        foo.bar unless !foo
        foo.bar unless foo.nil?
        
        foo && foo.bar
        foo && foo.bar(param1, param2)
        foo && foo.bar { |e| e.something }
        foo && foo.bar(param) { |e| e.something }
        
        # good
        foo&.bar
        foo&.bar(param1, param2)
        foo&.bar { |e| e.something }
        foo&.bar(param) { |e| e.something }
        
        foo.nil? || foo.bar
        !foo || foo.bar
        
        # Methods that `nil` will `respond_to?` should not be converted to
        # use safe navigation
        foo.to_i if foo
        Severity
        Category
        Status
        Source
        Language