Method has too many lines. [21/15] Open
def retrieve(params = {}, retrieve_all = true)
@last_retrieved = Time.now.to_i
uri = URI.parse "account/#{@account_id}/extension"
uri.query = URI.encode_www_form(params) unless params.empty?
res = @client.http.get do |req|
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [17/15] Open
def get_department_members(department_id)
department_id = department_id.to_s unless department_id.is_a? String
if department_id !~ /^[0-9]+$/
raise 'department_id parameter must be a positive integer'
end
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for retrieve is too high. [31.21/30] Open
def retrieve(params = {}, retrieve_all = true)
@last_retrieved = Time.now.to_i
uri = URI.parse "account/#{@account_id}/extension"
uri.query = URI.encode_www_form(params) unless params.empty?
res = @client.http.get do |req|
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method get_department_members
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def get_department_members(department_id)
department_id = department_id.to_s unless department_id.is_a? String
if department_id !~ /^[0-9]+$/
raise 'department_id parameter must be a positive integer'
end
- 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 retrieve
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def retrieve(params = {}, retrieve_all = true)
@last_retrieved = Time.now.to_i
uri = URI.parse "account/#{@account_id}/extension"
uri.query = URI.encode_www_form(params) unless params.empty?
res = @client.http.get do |req|
- 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
Use each_value
instead of each
. Open
@extensions_hash.each do |_, v|
- Read upRead up
- Exclude checks
This cop checks for uses of each_key
and each_value
Hash methods.
Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.
Example:
# bad
hash.keys.each { |k| p k }
hash.values.each { |v| p v }
hash.each { |k, _v| p k }
hash.each { |_k, v| p v }
# good
hash.each_key { |k| p k }
hash.each_value { |v| p v }
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if @extensions_hash.key?(extension_id)
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Favor modifier unless
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
unless extension_number.is_a? String
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if department_id !~ /^[0-9]+$/
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if extension.key?('id') && extension['id'] > 0
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?