nerdhub/hcking

View on GitHub
app/models/single_event.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Complex method SingleEvent#<=> (51.7)
Open

  def <=>(other)
    if (self.occurrence.year != other.occurrence.year) || (self.occurrence.month != other.occurrence.month) || (self.occurrence.day != other.occurrence.day)
      # not on same day
      return self.occurrence <=> other.occurrence
    elsif self.full_day
Severity: Minor
Found in app/models/single_event.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Complex method SingleEvent::search (43.6)
Open

  def self.search(search)
    search.strip!
    # Name + Description in Single Event
    sevents = today_or_in_future.name_or_description_like("%#{search}%")

Severity: Minor
Found in app/models/single_event.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Complex method SingleEvent#is_for_user? (31.6)
Open

  def is_for_user?(user)
    return true unless user
    # Let us be a little more verbose than the old code
    # !((self.event.tag_list & user.hate_list).length > 0 && self.users.exclude?(user))
    hated_tags_event = (self.event.tag_list & user.hate_list)
Severity: Minor
Found in app/models/single_event.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Method <=> has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def <=>(other)
    if (self.occurrence.year != other.occurrence.year) || (self.occurrence.month != other.occurrence.month) || (self.occurrence.day != other.occurrence.day)
      # not on same day
      return self.occurrence <=> other.occurrence
    elsif self.full_day
Severity: Minor
Found in app/models/single_event.rb - About 1 hr 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

Complex method SingleEvent#to_opengraph (26.7)
Open

  def to_opengraph
    ogdata = event.to_opengraph.merge({
      "og:title"       => name_with_date,
      "og:description" => short_description
    })
Severity: Minor
Found in app/models/single_event.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

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

  def is_for_user?(user)
    return true unless user
    # Let us be a little more verbose than the old code
    # !((self.event.tag_list & user.hate_list).length > 0 && self.users.exclude?(user))
    hated_tags_event = (self.event.tag_list & user.hate_list)
Severity: Minor
Found in app/models/single_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

Complex method SingleEvent#update_event (22.7)
Open

  def update_event
    if based_on_rule
      event.schedule.add_exception_time occurrence
      if event.schedule.rtimes.include? occurrence
        event.schedule.remove_recurrence_time occurrence
Severity: Minor
Found in app/models/single_event.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Avoid too many return statements within this method.
Open

        return time_comparison
Severity: Major
Found in app/models/single_event.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

            return self.full_name.downcase <=> other.full_name.downcase
    Severity: Major
    Found in app/models/single_event.rb - About 30 mins to fix

      There are no issues that match your filters.

      Category
      Status