lujanfernaud/prevy

View on GitHub
app/models/group.rb

Summary

Maintainability
A
3 hrs
Test Coverage

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

class Group < ApplicationRecord
  UPCOMING_EVENTS = 6
  RECENT_MEMBERS  = 8
  TOP_MEMBERS     = 12
  GROUPS_PER_PAGE = 24
Severity: Minor
Found in app/models/group.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.

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

class Group < ApplicationRecord
  UPCOMING_EVENTS = 6
  RECENT_MEMBERS  = 8
  TOP_MEMBERS     = 12
  GROUPS_PER_PAGE = 24
Severity: Minor
Found in app/models/group.rb - About 3 hrs to fix

    Group has at least 27 methods
    Open

    class Group < ApplicationRecord
    Severity: Minor
    Found in app/models/group.rb by reek

    Too Many Methods is a special case of LargeClass.

    Example

    Given this configuration

    TooManyMethods:
      max_methods: 3

    and this code:

    class TooManyMethods
      def one; end
      def two; end
      def three; end
      def four; end
    end

    Reek would emit the following warning:

    test.rb -- 1 warning:
      [1]:TooManyMethods has at least 4 methods (TooManyMethods)

    Group#image_base64 has the name 'image_base64'
    Open

      def image_base64
    Severity: Minor
    Found in app/models/group.rb by reek

    An Uncommunicative Method Name is a method name that doesn't communicate its intent well enough.

    Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

    Place the . on the next line, together with the method name.
    Open

        where(hidden: false, sample_group: false).
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop checks the . position in multi-line method calls.

    Example: EnforcedStyle: leading (default)

    # bad
    something.
      mehod
    
    # good
    something
      .method

    Example: EnforcedStyle: trailing

    # bad
    something
      .method
    
    # good
    something.
      mehod

    Use %i or %I for an array of symbols.
    Open

        against: [:name, :location, :description],
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop can check for array literals made up of symbols that are not using the %i() syntax.

    Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

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

    Example: EnforcedStyle: percent (default)

    # good
    %i[foo bar baz]
    
    # bad
    [:foo, :bar, :baz]

    Example: EnforcedStyle: brackets

    # good
    [:foo, :bar, :baz]
    
    # bad
    %i[foo bar baz]

    Use %i or %I for an array of symbols.
    Open

            [:name, :location],
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop can check for array literals made up of symbols that are not using the %i() syntax.

    Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

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

    Example: EnforcedStyle: percent (default)

    # good
    %i[foo bar baz]
    
    # bad
    [:foo, :bar, :baz]

    Example: EnforcedStyle: brackets

    # good
    [:foo, :bar, :baz]
    
    # bad
    %i[foo bar baz]

    Inconsistent indentation detected.
    Open

        def create_image_placeholder
          ImagePlaceholderCreator.new(self).call
        end
    Severity: Minor
    Found in app/models/group.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 update_members_role
          GroupMembersRoleUpdater.call(self)
        end
    Severity: Minor
    Found in app/models/group.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 should_generate_new_friendly_id?
          slug.blank? || saved_change_to_name?
        end
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cops checks for inconsistent indentation.

    Example:

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

    Missing top-level class documentation comment.
    Open

    class Group < ApplicationRecord
    Severity: Minor
    Found in app/models/group.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

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

      has_many :members, through: :group_memberships, source: "user"
    Severity: Minor
    Found in app/models/group.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 lambda method for multiline lambdas.
    Open

      scope :unhidden_without, -> (group) {
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.

    Example: EnforcedStyle: linecountdependent (default)

    # bad
    f = lambda { |x| x }
    f = ->(x) do
          x
        end
    
    # good
    f = ->(x) { x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: lambda

    # bad
    f = ->(x) { x }
    f = ->(x) do
          x
        end
    
    # good
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: literal

    # bad
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end
    
    # good
    f = ->(x) { x }
    f = ->(x) do
          x
        end

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

      has_many :received_requests, through: :membership_requests, source: "user"
    Severity: Minor
    Found in app/models/group.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 %i or %I for an array of symbols.
    Open

            [:name, :location, :owner_name, :owner_id]
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop can check for array literals made up of symbols that are not using the %i() syntax.

    Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

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

    Example: EnforcedStyle: percent (default)

    # good
    %i[foo bar baz]
    
    # bad
    [:foo, :bar, :baz]

    Example: EnforcedStyle: brackets

    # good
    [:foo, :bar, :baz]
    
    # bad
    %i[foo bar baz]

    Do not use spaces between -> and opening brace in lambda literals
    Open

      scope :unhidden_without, -> (group) {
        where(hidden: false, sample_group: false).
        where.not(id: group.id)
      }
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop checks for spaces between -> and opening parameter brace in lambda literals.

    Example: EnforcedStyle: requirenospace (default)

    # bad
      a = -> (x, y) { x + y }
    
      # good
      a = ->(x, y) { x + y }

    Example: EnforcedStyle: require_space

    # bad
      a = ->(x, y) { x + y }
    
      # good
      a = -> (x, y) { x + y }

    Inconsistent indentation detected.
    Open

        def slug_candidates
          [
            :name,
            [:name, :location],
            [:name, :location, :owner_name],
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cops checks for inconsistent indentation.

    Example:

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

    Use the lambda method for multiline lambdas.
    Open

      scope :unhidden, -> {
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.

    Example: EnforcedStyle: linecountdependent (default)

    # bad
    f = lambda { |x| x }
    f = ->(x) do
          x
        end
    
    # good
    f = ->(x) { x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: lambda

    # bad
    f = ->(x) { x }
    f = ->(x) do
          x
        end
    
    # good
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: literal

    # bad
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end
    
    # good
    f = ->(x) { x }
    f = ->(x) do
          x
        end

    Inconsistent indentation detected.
    Open

        def destroy_owner_group_points
          group_points = UserGroupPoints.find_by(user: owner, group: self)
    
          return unless group_points
    
    
    Severity: Minor
    Found in app/models/group.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 owner_name
          owner.name
        end
    Severity: Minor
    Found in app/models/group.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 prepare_text_fields
          self.name        = name.titleize
          self.location    = location.titleize
          self.description = description[0].capitalize + description[1..-1]
        end
    Severity: Minor
    Found in app/models/group.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 group_users_with_role(role)
          GroupUsersWithRoleQuery.call(self, role)
        end
    Severity: Minor
    Found in app/models/group.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 owner_id
          owner.id
        end
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cops checks for inconsistent indentation.

    Example:

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

    Do not use spaces between -> and opening brace in lambda literals
    Open

      scope :random_selection, -> (groups_number) {
        random_offset = rand(1..self.count - groups_number)
    
        offset(random_offset).limit(groups_number)
      }
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop checks for spaces between -> and opening parameter brace in lambda literals.

    Example: EnforcedStyle: requirenospace (default)

    # bad
      a = -> (x, y) { x + y }
    
      # good
      a = ->(x, y) { x + y }

    Example: EnforcedStyle: require_space

    # bad
      a = ->(x, y) { x + y }
    
      # good
      a = -> (x, y) { x + y }

    Inconsistent indentation detected.
    Open

        def create_owner_group_points
          UserGroupPoints.create!(user: owner, group: self)
        end
    Severity: Minor
    Found in app/models/group.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

      belongs_to :owner, class_name: "User", foreign_key: "user_id"
    Severity: Minor
    Found in app/models/group.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"

    Redundant self detected.
    Open

        random_offset = rand(1..self.count - groups_number)
    Severity: Minor
    Found in app/models/group.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

    Use %i or %I for an array of symbols.
    Open

            [:name, :location, :owner_name],
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop can check for array literals made up of symbols that are not using the %i() syntax.

    Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

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

    Example: EnforcedStyle: percent (default)

    # good
    %i[foo bar baz]
    
    # bad
    [:foo, :bar, :baz]

    Example: EnforcedStyle: brackets

    # good
    [:foo, :bar, :baz]
    
    # bad
    %i[foo bar baz]

    Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
    Open

        where.not(id: group.id)
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop checks the indentation of the method name part in method calls that span more than one line.

    Example: EnforcedStyle: aligned

    # bad
    while myvariable
    .b
      # do something
    end
    
    # good
    while myvariable
          .b
      # do something
    end
    
    # good
    Thing.a
         .b
         .c

    Example: EnforcedStyle: indented

    # good
    while myvariable
      .b
    
      # do something
    end

    Example: EnforcedStyle: indentedrelativeto_receiver

    # good
    while myvariable
            .a
            .b
    
      # do something
    end
    
    # good
    myvariable = Thing
                   .a
                   .b
                   .c

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

      belongs_to :owner, class_name: "User", foreign_key: "user_id"
    Severity: Minor
    Found in app/models/group.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"

    Align the parameters of a method call if they span more than one line.
    Open

        against: [:name, :location, :description],
        using:   { tsearch: { prefix: true } }
    Severity: Minor
    Found in app/models/group.rb by rubocop

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Inconsistent indentation detected.
    Open

        def add_owner_as_organizer_and_moderator
          owner.add_role :organizer, self
          owner.add_role :moderator, self
        end
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cops checks for inconsistent indentation.

    Example:

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

    Use the lambda method for multiline lambdas.
    Open

      scope :random_selection, -> (groups_number) {
    Severity: Minor
    Found in app/models/group.rb by rubocop

    This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.

    Example: EnforcedStyle: linecountdependent (default)

    # bad
    f = lambda { |x| x }
    f = ->(x) do
          x
        end
    
    # good
    f = ->(x) { x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: lambda

    # bad
    f = ->(x) { x }
    f = ->(x) do
          x
        end
    
    # good
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end

    Example: EnforcedStyle: literal

    # bad
    f = lambda { |x| x }
    f = lambda do |x|
          x
        end
    
    # good
    f = ->(x) { x }
    f = ->(x) do
          x
        end

    There are no issues that match your filters.

    Category
    Status