lib/yt/associations/has_reports.rb
Method define_reports_method
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
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
- Read upRead up
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
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]
- Read upRead up
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
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]
Consider simplifying this complex logical expression. Open
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