glitch-soc/mastodon

View on GitHub
app/models/trends/links.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Method calculate_scores has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def calculate_scores(preview_cards, at_time)
    items = preview_cards.map do |preview_card|
      expected  = preview_card.history.get(at_time - 1.day).accounts.to_f
      expected  = 1.0 if expected.zero?
      observed  = preview_card.history.get(at_time).accounts.to_f
Severity: Minor
Found in app/models/trends/links.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

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

  def request_review
    PreviewCardTrend.pluck('distinct language').flat_map do |language|
      score_at_threshold  = PreviewCardTrend.where(language: language, allowed: true).by_rank.ranked_below(options[:review_threshold]).first&.score || 0
      preview_card_trends = PreviewCardTrend.where(language: language, allowed: false).joins(:preview_card)

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

Method calculate_scores has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def calculate_scores(preview_cards, at_time)
    items = preview_cards.map do |preview_card|
      expected  = preview_card.history.get(at_time - 1.day).accounts.to_f
      expected  = 1.0 if expected.zero?
      observed  = preview_card.history.get(at_time).accounts.to_f
Severity: Minor
Found in app/models/trends/links.rb - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

        return unless (original_status.public_visibility? && status.public_visibility?) &&
                      !(original_status.account.silenced? || status.account.silenced?) &&
                      !(original_status.spoiler_text? || original_status.sensitive?)
    Severity: Major
    Found in app/models/trends/links.rb - About 40 mins to fix

      Method register has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def register(status, at_time = Time.now.utc)
          original_status = status.proper
      
          return unless (original_status.public_visibility? && status.public_visibility?) &&
                        !(original_status.account.silenced? || status.account.silenced?) &&
      Severity: Minor
      Found in app/models/trends/links.rb - About 35 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

      There are no issues that match your filters.

      Category
      Status