Method fetch_saved_report
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def fetch_saved_report(id)
rr = MiqReportResult.for_user(current_user).find_by(:id => id)
if rr.nil? # Saved report no longer exists
@report = nil
add_flash(_("Error: Report no longer exists in the database"), :error)
- Read upRead up
- Create a ticketCreate a ticket
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 fetch_saved_report
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def fetch_saved_report(id)
rr = MiqReportResult.for_user(current_user).find_by(:id => id)
if rr.nil? # Saved report no longer exists
@report = nil
add_flash(_("Error: Report no longer exists in the database"), :error)
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if @report.graph.present?
@render_chart = true
@ght_type = "hybrid"
else
@ght_type = "tabular"
- Create a ticketCreate a ticket
Avoid more than 3 levels of block nesting. Open
if rr.contains_records?
@html = report_first_page(rr) # Get the first page of the results
if @report.graph.present?
@render_chart = true
@ght_type = "hybrid"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
private
(on line 37) does not make singleton methods private. Use private_class_method
or private
inside a class << self
block instead. Open
def self.session_key_prefix
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for private
or protected
access modifiers which are
applied to a singleton method. These access modifiers do not make
singleton methods private/protected. private_class_method
can be
used for that.
Example:
# bad
class C
private
def self.method
puts 'hi'
end
end
Example:
# good
class C
def self.method
puts 'hi'
end
private_class_method :method
end
Example:
# good
class C
class << self
private
def method
puts 'hi'
end
end
end