ReadyResponder/ReadyResponder

View on GitHub
app/models/requirement.rb

Summary

Maintainability
A
1 hr
Test Coverage
A
94%

Assignment Branch Condition size for valid_people_numbers is too high. [21.84/15]
Open

    def valid_people_numbers
      if (minimum_people.present? and maximum_people.present? and desired_people.present?)
        if maximum_people < minimum_people
          errors.add :maximum_people, "must be greater than or equal to 'minimum_people'"
        end
Severity: Minor
Found in app/models/requirement.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. [12/10]
Open

  def status
    case
    when number_filled >= maximum_people
      return 'Full'
    when number_filled >= desired_people
Severity: Minor
Found in app/models/requirement.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 valid_title_or_skill is too high. [16.49/15]
Open

    def valid_title_or_skill
      if title.blank? && skill.blank?
        errors.add :title, "a requirement must have either a title or a skill"
        errors.add :skill, "a requirement must have either a title or a skill"
      end
Severity: Minor
Found in app/models/requirement.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 valid_people_numbers is too high. [7/6]
Open

    def valid_people_numbers
      if (minimum_people.present? and maximum_people.present? and desired_people.present?)
        if maximum_people < minimum_people
          errors.add :maximum_people, "must be greater than or equal to 'minimum_people'"
        end
Severity: Minor
Found in app/models/requirement.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 has too many lines. [11/10]
Open

    def valid_people_numbers
      if (minimum_people.present? and maximum_people.present? and desired_people.present?)
        if maximum_people < minimum_people
          errors.add :maximum_people, "must be greater than or equal to 'minimum_people'"
        end
Severity: Minor
Found in app/models/requirement.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 valid_people_numbers has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def valid_people_numbers
      if (minimum_people.present? and maximum_people.present? and desired_people.present?)
        if maximum_people < minimum_people
          errors.add :maximum_people, "must be greater than or equal to 'minimum_people'"
        end
Severity: Minor
Found in app/models/requirement.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

Avoid too many return statements within this method.
Open

      return 'Empty'
Severity: Major
Found in app/models/requirement.rb - About 30 mins to fix

    Use && instead of and.
    Open

          if (minimum_people.present? and maximum_people.present? and desired_people.present?)
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

    Example: EnforcedStyle: always (default)

    # bad
    foo.save and return
    
    # bad
    if foo and bar
    end
    
    # good
    foo.save && return
    
    # good
    if foo && bar
    end

    Example: EnforcedStyle: conditionals

    # bad
    if foo and bar
    end
    
    # good
    foo.save && return
    
    # good
    foo.save and return
    
    # good
    if foo && bar
    end

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

          if title.present? && skill.present?
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    Redundant return detected.
    Open

          return 'Satisfied'
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for redundant return expressions.

    Example:

    def test
      return something
    end
    
    def test
      one
      two
      three
      return something
    end

    It should be extended to handle methods whose body is if/else or a case expression with a default branch.

    Redundant return detected.
    Open

        return STATUS_CHOICES[status]
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for redundant return expressions.

    Example:

    def test
      return something
    end
    
    def test
      one
      two
      three
      return something
    end

    It should be extended to handle methods whose body is if/else or a case expression with a default branch.

    Extra blank line detected.
    Open

    
      STATUS_CHOICES_ARRAY = ['Empty', 'Inadequate', 'Adequate', 'Satisfied', 'Full']
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cops checks for two or more consecutive blank lines.

    Example:

    # bad - It has two empty lines.
    some_method
    # one empty line
    # two empty lines
    some_method
    
    # good
    some_method
    # one empty line
    some_method

    Line is too long. [89/80]
    Open

              errors.add :desired_people, "must be greater than or equal to 'minimum_people'"
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Use number_filled.positive? instead of number_filled > 0.
    Open

        when number_filled > 0
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

    The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

    The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

    Example: EnforcedStyle: predicate (default)

    # bad
    
    foo == 0
    0 > foo
    bar.baz > 0
    
    # good
    
    foo.zero?
    foo.negative?
    bar.baz.positive?

    Example: EnforcedStyle: comparison

    # bad
    
    foo.zero?
    foo.negative?
    bar.baz.positive?
    
    # good
    
    foo == 0
    0 > foo
    bar.baz > 0

    Line is too long. [81/80]
    Open

      STATUS_CHOICES_ARRAY = ['Empty', 'Inadequate', 'Adequate', 'Satisfied', 'Full']
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Line is too long. [89/80]
    Open

              errors.add :maximum_people, "must be greater than or equal to 'minimum_people'"
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Keep a blank line before and after private.
    Open

      private
    Severity: Minor
    Found in app/models/requirement.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

    Line is too long. [86/80]
    Open

              errors.add :desired_people, "must be less than or equal to 'maximum_people'"
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Redundant return detected.
    Open

          return 'Empty'
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for redundant return expressions.

    Example:

    def test
      return something
    end
    
    def test
      one
      two
      three
      return something
    end

    It should be extended to handle methods whose body is if/else or a case expression with a default branch.

    Line is too long. [110/80]
    Open

      validates :maximum_people, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Use && instead of and.
    Open

          if (minimum_people.present? and maximum_people.present? and desired_people.present?)
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

    Example: EnforcedStyle: always (default)

    # bad
    foo.save and return
    
    # bad
    if foo and bar
    end
    
    # good
    foo.save && return
    
    # good
    if foo && bar
    end

    Example: EnforcedStyle: conditionals

    # bad
    if foo and bar
    end
    
    # good
    foo.save && return
    
    # good
    foo.save and return
    
    # good
    if foo && bar
    end

    Missing magic comment # frozen_string_literal: true.
    Open

    class Requirement < ApplicationRecord
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

    Example: EnforcedStyle: when_needed (default)

    # The `when_needed` style will add the frozen string literal comment
    # to files only when the `TargetRubyVersion` is set to 2.3+.
    # bad
    module Foo
      # ...
    end
    
    # good
    # frozen_string_literal: true
    
    module Foo
      # ...
    end

    Example: EnforcedStyle: always

    # The `always` style will always add the frozen string literal comment
    # to a file, regardless of the Ruby version or if `freeze` or `<<` are
    # called on a string literal.
    # bad
    module Bar
      # ...
    end
    
    # good
    # frozen_string_literal: true
    
    module Bar
      # ...
    end

    Example: EnforcedStyle: never

    # The `never` will enforce that the frozen string literal comment does
    # not exist in a file.
    # bad
    # frozen_string_literal: true
    
    module Baz
      # ...
    end
    
    # good
    module Baz
      # ...
    end

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

            errors.add :title, "a requirement must have either a title or a skill"
    Severity: Minor
    Found in app/models/requirement.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 valid_title_or_skill
          if title.blank? && skill.blank?
            errors.add :title, "a requirement must have either a title or a skill"
            errors.add :skill, "a requirement must have either a title or a skill"
          end
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cops checks for inconsistent indentation.

    Example:

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

    Line is too long. [90/80]
    Open

          if (minimum_people.present? and maximum_people.present? and desired_people.present?)
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Line is too long. [110/80]
    Open

      validates :desired_people, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Don't use parentheses around the condition of an if.
    Open

          if (minimum_people.present? and maximum_people.present? and desired_people.present?)
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for the presence of superfluous parentheses around the condition of if/unless/while/until.

    Example:

    # bad
    x += 1 while (x < 10)
    foo unless (bar || baz)
    
    if (x > 10)
    elsif (x < 3)
    end
    
    # good
    x += 1 while x < 10
    foo unless bar || baz
    
    if x > 10
    elsif x < 3
    end

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

        true if ["Adequate", "Satisfied", "Full"].include? status
    Severity: Minor
    Found in app/models/requirement.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"

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

            errors.add :skill, "a requirement must have either a title or a skill"
    Severity: Minor
    Found in app/models/requirement.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"

    Use the new Ruby 1.9 hash syntax.
    Open

      delegate :event, :to => :task
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks hash literal syntax.

    It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).

    A separate offense is registered for each problematic pair.

    The supported styles are:

    • ruby19 - forces use of the 1.9 syntax (e.g. {a: 1}) when hashes have all symbols for keys
    • hash_rockets - forces use of hash rockets for all hashes
    • nomixedkeys - simply checks for hashes with mixed syntaxes
    • ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes

    Example: EnforcedStyle: ruby19 (default)

    # bad
    {:a => 2}
    {b: 1, :c => 2}
    
    # good
    {a: 2, b: 1}
    {:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
    {d: 1, 'e' => 2} # technically not forbidden

    Example: EnforcedStyle: hash_rockets

    # bad
    {a: 1, b: 2}
    {c: 1, 'd' => 5}
    
    # good
    {:a => 1, :b => 2}

    Example: EnforcedStyle: nomixedkeys

    # bad
    {:a => 1, b: 2}
    {c: 1, 'd' => 2}
    
    # good
    {:a => 1, :b => 2}
    {c: 1, d: 2}

    Example: EnforcedStyle: ruby19nomixed_keys

    # bad
    {:a => 1, :b => 2}
    {c: 2, 'd' => 3} # should just use hash rockets
    
    # good
    {a: 1, b: 2}
    {:c => 3, 'd' => 4}

    Redundant return detected.
    Open

          return 'Full'
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for redundant return expressions.

    Example:

    def test
      return something
    end
    
    def test
      one
      two
      three
      return something
    end

    It should be extended to handle methods whose body is if/else or a case expression with a default branch.

    Redundant return detected.
    Open

          return 'Adequate'
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for redundant return expressions.

    Example:

    def test
      return something
    end
    
    def test
      one
      two
      three
      return something
    end

    It should be extended to handle methods whose body is if/else or a case expression with a default branch.

    Freeze mutable objects assigned to constants.
    Open

      STATUS_CHOICES_ARRAY = ['Empty', 'Inadequate', 'Adequate', 'Satisfied', 'Full']
    Severity: Minor
    Found in app/models/requirement.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

    Use %w or %W for an array of words.
    Open

      STATUS_CHOICES_ARRAY = ['Empty', 'Inadequate', 'Adequate', 'Satisfied', 'Full']
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop can check for array literals made up of word-like strings, that are not using the %w() syntax.

    Alternatively, it can check for uses of the %w() syntax, in projects which do not want to include that syntax.

    Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of 3 will not enforce a style on an array of 2 or fewer elements.

    Example: EnforcedStyle: percent (default)

    # good
    %w[foo bar baz]
    
    # bad
    ['foo', 'bar', 'baz']

    Example: EnforcedStyle: brackets

    # good
    ['foo', 'bar', 'baz']
    
    # bad
    %w[foo bar baz]

    Use %w or %W for an array of words.
    Open

        true if ["Adequate", "Satisfied", "Full"].include? status
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop can check for array literals made up of word-like strings, that are not using the %w() syntax.

    Alternatively, it can check for uses of the %w() syntax, in projects which do not want to include that syntax.

    Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of 3 will not enforce a style on an array of 2 or fewer elements.

    Example: EnforcedStyle: percent (default)

    # good
    %w[foo bar baz]
    
    # bad
    ['foo', 'bar', 'baz']

    Example: EnforcedStyle: brackets

    # good
    ['foo', 'bar', 'baz']
    
    # bad
    %w[foo bar baz]

    Do not use empty case condition, instead use an if expression.
    Open

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

    This cop checks for case statements with an empty condition.

    Example:

    # bad:
    case
    when x == 0
      puts 'x is 0'
    when y == 0
      puts 'y is 0'
    else
      puts 'neither is 0'
    end
    
    # good:
    if x == 0
      puts 'x is 0'
    elsif y == 0
      puts 'y is 0'
    else
      puts 'neither is 0'
    end
    
    # good: (the case condition node is not empty)
    case n
    when 0
      puts 'zero'
    when 1
      puts 'one'
    else
      puts 'more'
    end

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

          if (minimum_people.present? and maximum_people.present? and desired_people.present?)
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    Missing top-level class documentation comment.
    Open

    class Requirement < ApplicationRecord
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

    The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

    Example:

    # bad
    class Person
      # ...
    end
    
    # good
    # Description/Explanation of Person class
    class Person
      # ...
    end

    Inconsistent indentation detected.
    Open

        def valid_people_numbers
          if (minimum_people.present? and maximum_people.present? and desired_people.present?)
            if maximum_people < minimum_people
              errors.add :maximum_people, "must be greater than or equal to 'minimum_people'"
            end
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cops checks for inconsistent indentation.

    Example:

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

    Freeze mutable objects assigned to constants.
    Open

      PRIORITIES = [['High', 1], ['Medium', 2], ['Low', 3]]
    Severity: Minor
    Found in app/models/requirement.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

    Redundant return detected.
    Open

          return 'Inadequate'
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    This cop checks for redundant return expressions.

    Example:

    def test
      return something
    end
    
    def test
      one
      two
      three
      return something
    end

    It should be extended to handle methods whose body is if/else or a case expression with a default branch.

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

        "Error"
    Severity: Minor
    Found in app/models/requirement.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"

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

        true if ["Adequate", "Satisfied", "Full"].include? status
    Severity: Minor
    Found in app/models/requirement.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"

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

        true if ["Adequate", "Satisfied", "Full"].include? status
    Severity: Minor
    Found in app/models/requirement.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"

    Line is too long. [110/80]
    Open

      validates :minimum_people, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Pass &:person as an argument to map instead of a block.
    Open

        assignments.active.map { |a| a.person }
    Severity: Minor
    Found in app/models/requirement.rb by rubocop

    Use symbols as procs when possible.

    Example:

    # bad
    something.map { |s| s.upcase }
    
    # good
    something.map(&:upcase)

    There are no issues that match your filters.

    Category
    Status