lujanfernaud/prevy

View on GitHub
app/models/event.rb

Summary

Maintainability
A
2 hrs
Test Coverage

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

class Event < ApplicationRecord
  RECENT_ATTENDEES = 8
  RANDOM_ATTENDEES = 6
  EVENTS_PER_PAGE  = 15

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.

Class Event has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

class Event < ApplicationRecord
  RECENT_ATTENDEES = 8
  RANDOM_ATTENDEES = 6
  EVENTS_PER_PAGE  = 15

Severity: Minor
Found in app/models/event.rb - About 2 hrs to fix

    Event has at least 23 methods
    Open

    class Event < ApplicationRecord
    Severity: Minor
    Found in app/models/event.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)

    Event#default_end_date calls '1.hour' 2 times
    Open

        (1.week.from_now + 1.hour).round_to(1.hour)
    Severity: Minor
    Found in app/models/event.rb by reek

    Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

    Reek implements a check for Duplicate Method Call.

    Example

    Here's a very much simplified and contrived example. The following method will report a warning:

    def double_thing()
      @other.thing + @other.thing
    end

    One quick approach to silence Reek would be to refactor the code thus:

    def double_thing()
      thing = @other.thing
      thing + thing
    end

    A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

    class Other
      def double_thing()
        thing + thing
      end
    end

    The approach you take will depend on balancing other factors in your code.

    Event#default_start_date doesn't depend on instance state (maybe move it to another class?)
    Open

      def default_start_date
    Severity: Minor
    Found in app/models/event.rb by reek

    A Utility Function is any instance method that has no dependency on the state of the instance.

    Event#default_end_date doesn't depend on instance state (maybe move it to another class?)
    Open

      def default_end_date
    Severity: Minor
    Found in app/models/event.rb by reek

    A Utility Function is any instance method that has no dependency on the state of the instance.

    Event#image_base64 has the name 'image_base64'
    Open

      def image_base64
    Severity: Minor
    Found in app/models/event.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.

    Unnecessary spacing detected.
    Open

      validates :title,       presence: true, length: { in: 4..140 }
    Severity: Minor
    Found in app/models/event.rb by rubocop

    This cop checks for extra/unnecessary whitespace.

    Example:

    # good if AllowForAlignment is true
    name      = "RuboCop"
    # Some comment and an empty line
    
    website  += "/bbatsov/rubocop" unless cond
    puts        "rubocop"          if     debug
    
    # bad for any configuration
    set_app("RuboCop")
    website  = "https://github.com/bbatsov/rubocop"

    Inconsistent indentation detected.
    Open

        def store_updated_start_date
          self.updated_start_date = start_date if start_date_changed?
        end
    Severity: Minor
    Found in app/models/event.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_title?
        end
    Severity: Minor
    Found in app/models/event.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_event_topic
          build_event_topic(
            user:  organizer,
            group: group,
            title: title,
    Severity: Minor
    Found in app/models/event.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 format_website_url
          WebsiteUrlFormatter.call(self)
        end
    Severity: Minor
    Found in app/models/event.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_event_topic
          topic.title = title       if title_changed?
          topic.body  = description if description_changed?
          topic.save
        end
    Severity: Minor
    Found in app/models/event.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 clear_previously_updated_fields
          self.updated_fields.clear
        end
    Severity: Minor
    Found in app/models/event.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 slug_candidates
          [
            :title,
            [:title, :date],
            [:title, :date, :group_id]
    Severity: Minor
    Found in app/models/event.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_id
          group.id
        end
    Severity: Minor
    Found in app/models/event.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 store_updated_fields
          clear_previously_updated_fields
    
          store_updated_start_date
          store_updated_end_date
    Severity: Minor
    Found in app/models/event.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

      has_many :attendances, foreign_key: "attended_event_id", dependent: :destroy
    Severity: Minor
    Found in app/models/event.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

        where("end_date < ?", Time.zone.now).order("end_date ASC")
    Severity: Minor
    Found in app/models/event.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

          self.updated_fields.clear
    Severity: Minor
    Found in app/models/event.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

            [:title, :date, :group_id]
    Severity: Minor
    Found in app/models/event.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]

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

                to: :address, allow_nil: true
    Severity: Minor
    Found in app/models/event.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

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

      has_many :comments,    through: :event_topic, source: "topic_comments"
    Severity: Minor
    Found in app/models/event.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 store_updated_end_date
          self.updated_end_date = end_date if end_date_changed?
        end
    Severity: Minor
    Found in app/models/event.rb by rubocop

    This cops checks for inconsistent indentation.

    Example:

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

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

            [:title, :date],
    Severity: Minor
    Found in app/models/event.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 date
          start_date.strftime("%b %d %Y")
        end
    Severity: Minor
    Found in app/models/event.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 :organizer, class_name: "User"
    Severity: Minor
    Found in app/models/event.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

        where("end_date > ?", Time.zone.now).order("start_date ASC")
    Severity: Minor
    Found in app/models/event.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 create_image_placeholder
          ImagePlaceholderCreator.new(self).call
        end
    Severity: Minor
    Found in app/models/event.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 Event < ApplicationRecord
    Severity: Minor
    Found in app/models/event.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

    Use the lambda method for multiline lambdas.
    Open

      scope :past, -> {
    Severity: Minor
    Found in app/models/event.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 no_past_date
          if start_date < Time.zone.now
            errors.add(:start_date, "can't be in the past")
          elsif end_date < start_date
            errors.add(:start_date, "can't be later than end date")
    Severity: Minor
    Found in app/models/event.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 titleize_title
          self.title = title.titleize
        end
    Severity: Minor
    Found in app/models/event.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 store_updated_address
          self.updated_address = full_address if full_address_changed?
        end
    Severity: Minor
    Found in app/models/event.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

        where("end_date > ?", Time.zone.now).order("start_date ASC")
    Severity: Minor
    Found in app/models/event.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

        where("end_date < ?", Time.zone.now).order("end_date ASC")
    Severity: Minor
    Found in app/models/event.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 :upcoming, -> {
    Severity: Minor
    Found in app/models/event.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

          start_date.strftime("%b %d %Y")
    Severity: Minor
    Found in app/models/event.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