hpi-swt2/workshop-portal

View on GitHub
app/models/agreement_letter.rb

Summary

Maintainability
A
0 mins
Test Coverage

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.

Inconsistent indentation detected.
Open

    def too_big?(file)
      file.size > MAX_SIZE
    end
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Inconsistent indentation detected.
Open

    def wrong_filetype?(file)
      file.content_type != ALLOWED_MIMETYPE
    end
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Trailing whitespace detected.
Open

    
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

Inconsistent indentation detected.
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 cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

        errors.add(:file, I18n.t("agreement_letters.file_too_big"))
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Keep a blank line before and after private.
Open

  private
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

Access modifiers should be surrounded by blank lines.

Example:

# bad
class Foo
  def bar; end
  private
  def baz; end
end

# good
class Foo
  def bar; end

  private

  def baz; end
end

Freeze mutable objects assigned to constants.
Open

  ALLOWED_MIMETYPE = "application/pdf"
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

        errors.add(:file, I18n.t("agreement_letters.not_a_file"))
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Rename is_file? to file?.
Open

    def is_file?(file)
Severity: Minor
Found in app/models/agreement_letter.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

Redundant self detected.
Open

      self.destroy
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Line is too long. [91/80]
Open

      file.respond_to?(:open) && file.respond_to?(:content_type) && file.respond_to?(:size)
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

Line is too long. [84/80]
Open

  # Sets the AgreementLetter's path field to the path where the file should be saved
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

        errors.add(:file, I18n.t("agreement_letters.wrong_filetype"))
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Inconsistent indentation detected.
Open

    def is_file?(file)
      file.respond_to?(:open) && file.respond_to?(:content_type) && file.respond_to?(:size)
    end
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Redundant self detected.
Open

      self.destroy
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

  ALLOWED_MIMETYPE = "application/pdf"
Severity: Minor
Found in app/models/agreement_letter.rb by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

There are no issues that match your filters.

Category
Status