wazery/ratyrate

View on GitHub

Showing 5 of 5 total issues

Method rating_for has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def rating_for(rateable_obj, dimension=nil, options={})

      cached_average = rateable_obj.average dimension
      avg = cached_average ? cached_average.avg : 0

Severity: Major
Found in lib/ratyrate/helpers.rb - About 2 hrs to fix

    Method rating_for has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def rating_for(rateable_obj, dimension=nil, options={})
    
          cached_average = rateable_obj.average dimension
          avg = cached_average ? cached_average.avg : 0
    
    
    Severity: Minor
    Found in lib/ratyrate/helpers.rb - About 2 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

    Method rating_for_user has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def rating_for_user(rateable_obj, rating_user, dimension = nil, options = {})
          @object = rateable_obj
          @user   = rating_user
            @rating = Rate.find_by rater: @user, rateable: @object, dimension: dimension
            stars = @rating ? @rating.stars : 0
    Severity: Major
    Found in lib/ratyrate/helpers.rb - About 2 hrs to fix

      Method rating_for_user has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def rating_for_user(rateable_obj, rating_user, dimension = nil, options = {})
            @object = rateable_obj
            @user   = rating_user
              @rating = Rate.find_by rater: @user, rateable: @object, dimension: dimension
              stars = @rating ? @rating.stars : 0
      Severity: Minor
      Found in lib/ratyrate/helpers.rb - About 55 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

      Method rate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def rate(stars, user, dimension=nil, dirichlet_method=false)
            dimension = nil if dimension.blank?
      
            if can_rate? user, dimension
              rates(dimension).create! do |r|
      Severity: Minor
      Found in lib/ratyrate/model.rb - About 25 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

      Severity
      Category
      Status
      Source
      Language