Fullscreen/yt

View on GitHub
lib/yt/associations/has_reports.rb

Summary

Maintainability
C
1 day
Test Coverage

Method define_reports_method has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

      def define_reports_method(metric, type)
        (@metrics ||= {})[metric] = type
        define_method :reports do |options = {}|
          from = options[:since] || options[:from] || (options[:by].in?([:day, :month]) ? 5.days.ago : '2005-02-01')
          to = options[:until] || options[:to] || Date.today
Severity: Minor
Found in lib/yt/associations/has_reports.rb - About 3 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 define_metric_method has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

      def define_metric_method(metric)
        define_method metric do |options = {}|
          from = options[:since] || options[:from] || (options[:by].in?([:day, :month]) ? 5.days.ago : '2005-02-01')
          to = options[:until] || options[:to] || Date.today
          location = options[:in]
Severity: Minor
Found in lib/yt/associations/has_reports.rb - About 3 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 define_metric_method has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def define_metric_method(metric)
        define_method metric do |options = {}|
          from = options[:since] || options[:from] || (options[:by].in?([:day, :month]) ? 5.days.ago : '2005-02-01')
          to = options[:until] || options[:to] || Date.today
          location = options[:in]
Severity: Minor
Found in lib/yt/associations/has_reports.rb - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

            define_method :reports do |options = {}|
              from = options[:since] || options[:from] || (options[:by].in?([:day, :month]) ? 5.days.ago : '2005-02-01')
              to = options[:until] || options[:to] || Date.today
              location = options[:in]
              country = location.is_a?(Hash) ? location[:country] : location
    Severity: Major
    Found in lib/yt/associations/has_reports.rb - About 40 mins to fix

      There are no issues that match your filters.

      Category
      Status