assemblymade/coderwall

View on GitHub
app/structs/audience.rb

Summary

Maintainability
C
1 day
Test Coverage

Method expand has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

  def self.expand(audience)
    audience.keys.map(&:to_sym).collect do |target|

      if target == :user_reach
        user = User.find(audience[target])
Severity: Minor
Found in app/structs/audience.rb - About 6 hrs 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

Class Audience has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

class Audience
  def self.all
    { all: nil }
  end

Severity: Minor
Found in app/structs/audience.rb - About 2 hrs to fix

    Method expand has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.expand(audience)
        audience.keys.map(&:to_sym).collect do |target|
    
          if target == :user_reach
            user = User.find(audience[target])
    Severity: Minor
    Found in app/structs/audience.rb - About 1 hr to fix

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

        def self.expand_reach(user_or_team)
          audiences = []
          audiences.concat(expand_followers(user_or_team))
      
          if user_or_team.is_a?(Team)
      Severity: Minor
      Found in app/structs/audience.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 deeply nested control flow statements.
      Open

              expand_followers(user) unless user.nil?
      Severity: Major
      Found in app/structs/audience.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

              elsif target == :team_followers
                team = Team.find(audience[target])
                expand_followers(team) unless team.nil?
              elsif target == :all
                expand_all_users
        Severity: Major
        Found in app/structs/audience.rb - About 45 mins to fix

          There are no issues that match your filters.

          Category
          Status