ece517-p3/expertiza

View on GitHub
app/models/assignment_team.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Mass assignment is not restricted using attr_accessible
Open

class AssignmentTeam < Team
Severity: Critical
Found in app/models/assignment_team.rb by brakeman

This warning comes up if a model does not limit what attributes can be set through mass assignment.

In particular, this check looks for attr_accessible inside model definitions. If it is not found, this warning will be issued.

Brakeman also warns on use of attr_protected - especially since it was found to be vulnerable to bypass. Warnings for mass assignment on models using attr_protected will be reported, but at a lower confidence level.

Note that disabling mass assignment globally will suppress these warnings.

Class AssignmentTeam has 31 methods (exceeds 20 allowed). Consider refactoring.
Open

class AssignmentTeam < Team
  require File.dirname(__FILE__) + '/analytic/assignment_team_analytic'
  include AssignmentTeamAnalytic

  belongs_to :assignment, class_name: 'Assignment', foreign_key: 'parent_id'
Severity: Minor
Found in app/models/assignment_team.rb - About 3 hrs to fix

    Assignment Branch Condition size for scores is too high. [18.97/15]
    Open

      def scores(questions)
        scores = {}
        scores[:team] = self # This doesn't appear to be used anywhere
        assignment.questionnaires.each do |questionnaire|
          scores[questionnaire.symbol] = {}
    Severity: Minor
    Found in app/models/assignment_team.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Specify an :inverse_of option.
    Open

      belongs_to :assignment, class_name: 'Assignment', foreign_key: 'parent_id'
    Severity: Minor
    Found in app/models/assignment_team.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 a :dependent option.
    Open

      has_many :review_mappings, class_name: 'ReviewResponseMap', foreign_key: 'reviewee_id'
    Severity: Minor
    Found in app/models/assignment_team.rb by rubocop

    This cop looks for has_many or has_one associations that don't specify a :dependent option. It doesn't register an offense if :through option was specified.

    Example:

    # bad
    class User < ActiveRecord::Base
      has_many :comments
      has_one :avatar
    end
    
    # good
    class User < ActiveRecord::Base
      has_many :comments, dependent: :restrict_with_exception
      has_one :avatar, dependent: :destroy
      has_many :patients, through: :appointments
    end

    Specify a :dependent option.
    Open

      has_many :review_response_maps, foreign_key: 'reviewee_id'
    Severity: Minor
    Found in app/models/assignment_team.rb by rubocop

    This cop looks for has_many or has_one associations that don't specify a :dependent option. It doesn't register an offense if :through option was specified.

    Example:

    # bad
    class User < ActiveRecord::Base
      has_many :comments
      has_one :avatar
    end
    
    # good
    class User < ActiveRecord::Base
      has_many :comments, dependent: :restrict_with_exception
      has_one :avatar, dependent: :destroy
      has_many :patients, through: :appointments
    end

    Specify an :inverse_of option.
    Open

      has_many :review_mappings, class_name: 'ReviewResponseMap', foreign_key: 'reviewee_id'
    Severity: Minor
    Found in app/models/assignment_team.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

      has_many :review_response_maps, foreign_key: 'reviewee_id'
    Severity: Minor
    Found in app/models/assignment_team.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

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

      def files(directory)
        files_list = Dir[directory + "/*"]
        files = []
    
        files_list.each do |file|
    Severity: Minor
    Found in app/models/assignment_team.rb and 1 other location - About 35 mins to fix
    app/models/assignment_participant.rb on lines 177..188

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

    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

    Rename has_submissions? to submissions?.
    Open

      def has_submissions?
    Severity: Minor
    Found in app/models/assignment_team.rb by rubocop

    This cop makes sure that predicates are named properly.

    Example:

    # bad
    def is_even?(value)
    end
    
    # good
    def even?(value)
    end
    
    # bad
    def has_value?
    end
    
    # good
    def value?
    end

    There are no issues that match your filters.

    Category
    Status