hpi-swt2/workshop-portal

View on GitHub

Showing 494 of 494 total issues

Class has too many lines. [106/100]
Open

class Event < ActiveRecord::Base
  UNREASONABLY_LONG_DATE_SPAN = 300

  has_many :application_letters
  has_many :agreement_letters
Severity: Minor
Found in app/models/event.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for dropdown_items is too high. [36.14/15]
Open

  def dropdown_items
    o = ''
    # everyone gets settings
    o << (menu_item t(:settings, scope: 'navbar'), edit_user_registration_path)
    # everyone gets their profile, if it exists
Severity: Minor
Found in app/helpers/application_helper.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

Method has too many lines. [22/10]
Open

  def initialize(user)
    # Define abilities for the passed in user here. For example:
    #
    #   user ||= User.new # guest user (not logged in)
    #   if user.admin?
Severity: Minor
Found in app/models/ability.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for create is too high. [24.92/15]
Open

  def create
    event_id = params[:event_id]
    @agreement_letter = AgreementLetter.where(user: current_user, event_id: event_id).take
    if @agreement_letter.nil?
      @agreement_letter = AgreementLetter.new

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

Assignment Branch Condition size for older_than_required_age_at_start_date_of_event? is too high. [24.52/15]
Open

  def older_than_required_age_at_start_date_of_event?(given_event, age)
    return false unless self.profile
    event_start = given_event.start_date
    event_start_is_before_birthday = event_start.month > self.profile.birth_date.month || (event_start.month == self.profile.birth_date.month && event_start.day >= self.profile.birth_date.day)
    age_at_event_start = event_start.year - self.profile.birth_date.year - (event_start_is_before_birthday ? 0 : 1)
Severity: Minor
Found in app/models/user.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

Method has too many lines. [19/10]
Open

  def compare_participants_by_agreement(participant1, participant2)
    if participant1.requires_agreement_letter_for_event?(self)
      if participant2.requires_agreement_letter_for_event?(self)
        return participant1.name <=> participant2.name
      end
Severity: Minor
Found in app/models/event.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [16/10]
Open

  def create
    event_id = params[:event_id]
    @agreement_letter = AgreementLetter.where(user: current_user, event_id: event_id).take
    if @agreement_letter.nil?
      @agreement_letter = AgreementLetter.new

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [15/10]
Open

  def dropdown_items
    o = ''
    # everyone gets settings
    o << (menu_item t(:settings, scope: 'navbar'), edit_user_registration_path)
    # everyone gets their profile, if it exists
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for initialize is too high. [20.71/15]
Open

  def initialize(user)
    # Define abilities for the passed in user here. For example:
    #
    #   user ||= User.new # guest user (not logged in)
    #   if user.admin?
Severity: Minor
Found in app/models/ability.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

Assignment Branch Condition size for age is too high. [20.32/15]
Open

  def age
    now = Time.now.utc.to_date
    current_time_is_before_birthday = now.month > birth_date.month || (now.month == birth_date.month && now.day >= birth_date.day)
    return now.year - birth_date.year - (current_time_is_before_birthday ? 0 : 1)
  end
Severity: Minor
Found in app/models/profile.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

Assignment Branch Condition size for new is too high. [19.52/15]
Open

  def new
    if not current_user
      message = I18n.t('application_letters.login_before_creation')
      return redirect_to user_session_path, :alert => message
    elsif not current_user.profile.present?

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

Method has too many lines. [12/10]
Open

    def valid_file?(file)
      if !is_file?(file)
        errors.add(:file, I18n.t("agreement_letters.not_a_file"))
        false
      elsif too_big?(file)
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [12/10]
Open

  def save_file(file)
    unless valid_file?(file)
      self.destroy
      return false
    end
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [11/10]
Open

  def new
    if not current_user
      message = I18n.t('application_letters.login_before_creation')
      return redirect_to user_session_path, :alert => message
    elsif not current_user.profile.present?

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [11/10]
Open

  def create
    @profile = Profile.new(profile_params)
    @profile.user_id = current_user.id

    if @profile.save

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for compare_participants_by_agreement is too high. [16.16/15]
Open

  def compare_participants_by_agreement(participant1, participant2)
    if participant1.requires_agreement_letter_for_event?(self)
      if participant2.requires_agreement_letter_for_event?(self)
        return participant1.name <=> participant2.name
      end
Severity: Minor
Found in app/models/event.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

Cyclomatic complexity for compare_participants_by_agreement is too high. [7/6]
Open

  def compare_participants_by_agreement(participant1, participant2)
    if participant1.requires_agreement_letter_for_event?(self)
      if participant2.requires_agreement_letter_for_event?(self)
        return participant1.name <=> participant2.name
      end
Severity: Minor
Found in app/models/event.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

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

  def compare_participants_by_agreement(participant1, participant2)
    if participant1.requires_agreement_letter_for_event?(self)
      if participant2.requires_agreement_letter_for_event?(self)
        return participant1.name <=> participant2.name
      end
Severity: Minor
Found in app/models/event.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

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

  def self.send_generic_email(hide_recipients, recipients, reply_to, subject, content)
Severity: Minor
Found in app/services/mailer.rb - About 35 mins to fix

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

      def initialize(user)
        # Define abilities for the passed in user here. For example:
        #
        #   user ||= User.new # guest user (not logged in)
        #   if user.admin?
    Severity: Minor
    Found in app/models/ability.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

    Severity
    Category
    Status
    Source
    Language