Module has too many lines. [181/100] Open
module OaiZoom
unless included_modules.include? OaiZoom
def self.included(klass)
klass.send :include, OaiDcHelpers
klass.send :include, ZoomHelpers
- Read upRead up
- Exclude checks
This cop checks if the length a module exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [57/10] Open
def oai_record_xml(options = {})
item = options[:item] || self
request = @import_request || simulated_request
record =
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
- 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 importer_oai_dc_xml_dc_relations_and_subjects is too high. [53.8/15] Open
def importer_oai_dc_xml_dc_relations_and_subjects(xml, item, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
- 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
Assignment Branch Condition size for oai_record_xml is too high. [43.29/15] Open
def oai_record_xml(options = {})
item = options[:item] || self
request = @import_request || simulated_request
record =
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
- 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 has too many lines. [35/10] Open
def importer_oai_dc_xml_dc_relations_and_subjects(xml, item, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
- 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. [33/10] Open
def prepare_and_save_to_zoom(options = {})
public_existing_connection = options[:public_existing_connection]
private_existing_connection = options[:private_existing_connection]
import_private = options[:import_private]
- 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 prepare_and_save_to_zoom is too high. [34.93/15] Open
def prepare_and_save_to_zoom(options = {})
public_existing_connection = options[:public_existing_connection]
private_existing_connection = options[:private_existing_connection]
import_private = options[:import_private]
- 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 importer_oai_dc_xml_dc_relations_and_subjects
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def importer_oai_dc_xml_dc_relations_and_subjects(xml, item, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
- 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 prepare_and_save_to_zoom
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def prepare_and_save_to_zoom(options = {})
public_existing_connection = options[:public_existing_connection]
private_existing_connection = options[:private_existing_connection]
import_private = options[:import_private]
- 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
Perceived complexity for prepare_and_save_to_zoom is too high. [19/7] Open
def prepare_and_save_to_zoom(options = {})
public_existing_connection = options[:public_existing_connection]
private_existing_connection = options[:private_existing_connection]
import_private = options[:import_private]
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Cyclomatic complexity for prepare_and_save_to_zoom is too high. [17/6] Open
def prepare_and_save_to_zoom(options = {})
public_existing_connection = options[:public_existing_connection]
private_existing_connection = options[:private_existing_connection]
import_private = options[:import_private]
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Block has too many lines. [49/25] Open
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
xml.send(
'OAI-PMH',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Method oai_record_xml
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def oai_record_xml(options = {})
item = options[:item] || self
request = @import_request || simulated_request
record =
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
Perceived complexity for importer_oai_dc_xml_dc_relations_and_subjects is too high. [9/7] Open
def importer_oai_dc_xml_dc_relations_and_subjects(xml, item, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Cyclomatic complexity for importer_oai_dc_xml_dc_relations_and_subjects is too high. [8/6] Open
def importer_oai_dc_xml_dc_relations_and_subjects(xml, item, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Assignment Branch Condition size for importer_oai_dc_xml_dc_rights is too high. [16.76/15] Open
def importer_oai_dc_xml_dc_rights(xml, item, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
- 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 has too many lines. [11/10] Open
def importer_oai_dc_xml_dc_rights(xml, item, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
- 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.
Block has too many lines. [42/25] Open
xml.send(
'OAI-PMH',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
'xmlns' => 'http://www.openarchives.org/OAI/2.0/'
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Block has too many lines. [38/25] Open
xml.GetRecord do
xml.record do
xml.header do
oai_dc_xml_oai_identifier(xml)
oai_dc_xml_oai_datestamp(xml)
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Method importer_oai_dc_xml_dc_relations_and_subjects
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def importer_oai_dc_xml_dc_relations_and_subjects(xml, item, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
Method prepare_and_save_to_zoom
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def prepare_and_save_to_zoom(options = {})
public_existing_connection = options[:public_existing_connection]
private_existing_connection = options[:private_existing_connection]
import_private = options[:import_private]
Block has too many lines. [36/25] Open
xml.record do
xml.header do
oai_dc_xml_oai_identifier(xml)
oai_dc_xml_oai_datestamp(xml)
oai_dc_xml_oai_set_specs(xml)
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Method oai_record_xml
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def oai_record_xml(options = {})
item = options[:item] || self
request = @import_request || simulated_request
record =
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
- 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
Consider simplifying this complex logical expression. Open
if !skip_private &&
(respond_to?(:private) && has_private_version? && !private?) ||
(is_a?(Comment) && commentable_private)
# have to reset self.oai_record, so that private version gets loaded in
Method importer_oai_dc_xml_dc_rights
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def importer_oai_dc_xml_dc_rights(xml, item, passed_request = nil)
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
- 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
Avoid more than 3 levels of block nesting. Open
if write_files
# write oai_record to appropriate directory for later indexing by zebraidx
write_oai_record_file('private')
else
zoom_save(private_existing_connection)
- Read upRead up
- Exclude checks
This cop 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.
Avoid more than 3 levels of block nesting. Open
if write_files
# write oai_record to appropriate directory for later indexing by zebraidx
write_oai_record_file('public')
else
zoom_save(public_existing_connection)
- Read upRead up
- Exclude checks
This cop 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.
TODO found Open
# TODO: this may not be needed anymore
- Exclude checks
HACK found Open
# HACK, brittle, but can't use url_for here
- Exclude checks
TODO found Open
# TODO: probably no longer needed
- Exclude checks
TODO found Open
# TODO: this may not be needed anymore
- Exclude checks
Favor format
over String#%
. Open
('%012d' % id).scan(/..../).join('/')
- Read upRead up
- Exclude checks
This cop enforces the use of a single string formatting utility. Valid options include Kernel#format, Kernel#sprintf and String#%.
The detection of String#% cannot be implemented in a reliable manner for all cases, so only two scenarios are considered - if the first argument is a string literal and if the second argument is an array literal.
Example: EnforcedStyle: format(default)
# bad
puts sprintf('%10s', 'hoge')
puts '%10s' % 'hoge'
# good
puts format('%10s', 'hoge')
Example: EnforcedStyle: sprintf
# bad
puts format('%10s', 'hoge')
puts '%10s' % 'hoge'
# good
puts sprintf('%10s', 'hoge')
Example: EnforcedStyle: percent
# bad
puts format('%10s', 'hoge')
puts sprintf('%10s', 'hoge')
# good
puts '%10s' % 'hoge'
Redundant curly braces around a hash parameter. Open
rights = importer_item_url({ host: host, controller: 'topics', item: item, urlified_name: Basket.find(SystemSetting.about_basket).urlified_name, id: 4, locale: false })
- Read upRead up
- Exclude checks
This cop checks for braces around the last parameter in a method call
if the last parameter is a hash.
It supports braces
, no_braces
and context_dependent
styles.
Example: EnforcedStyle: braces
# The `braces` style enforces braces around all method
# parameters that are hashes.
# bad
some_method(x, y, a: 1, b: 2)
# good
some_method(x, y, {a: 1, b: 2})
Example: EnforcedStyle: no_braces (default)
# The `no_braces` style checks that the last parameter doesn't
# have braces around it.
# bad
some_method(x, y, {a: 1, b: 2})
# good
some_method(x, y, a: 1, b: 2)
Example: EnforcedStyle: context_dependent
# The `context_dependent` style checks that the last parameter
# doesn't have braces around it, but requires braces if the
# second to last parameter is also a hash literal.
# bad
some_method(x, y, {a: 1, b: 2})
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
# good
some_method(x, y, a: 1, b: 2)
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
Use the return of the conditional for variable assignment and comparison. Open
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
end
- Exclude checks
Use the return of the conditional for variable assignment and comparison. Open
if item.respond_to?(:license) && !item.license.blank?
rights = item.license.url
else
rights = importer_item_url({ host: host, controller: 'topics', item: item, urlified_name: Basket.find(SystemSetting.about_basket).urlified_name, id: 4, locale: false })
end
- Exclude checks
Favor a normal unless-statement over a modifier clause in a multiline statement. Open
xml.send('dc:subject') do
xml.cdata commented_on_item.title
end unless [SystemSetting.blank_title, SystemSetting.no_public_version_title].include?(commented_on_item.title)
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Use the return of the conditional for variable assignment and comparison. Open
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
end
- Exclude checks
Favor a normal if-statement over a modifier clause in a multiline statement. Open
xml.send('dc:subject') do
xml.cdata item.url
end if item.is_a?(WebLink)
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Useless assignment to variable - import_private
. Open
import_private = options[:import_private]
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Use the return of the conditional for variable assignment and comparison. Open
if zoom_class == 'Topic'
related_items = item.related_topics
else
related_items = item.send(zoom_class.tableize)
end
- Exclude checks
Redundant curly braces around a hash parameter. Open
xml.send('dc:identifier', fully_qualified_item_url({ host: host, controller: zoom_class_controller(item.class.name), item: item, urlified_name: item.basket.urlified_name, locale: false }))
- Read upRead up
- Exclude checks
This cop checks for braces around the last parameter in a method call
if the last parameter is a hash.
It supports braces
, no_braces
and context_dependent
styles.
Example: EnforcedStyle: braces
# The `braces` style enforces braces around all method
# parameters that are hashes.
# bad
some_method(x, y, a: 1, b: 2)
# good
some_method(x, y, {a: 1, b: 2})
Example: EnforcedStyle: no_braces (default)
# The `no_braces` style checks that the last parameter doesn't
# have braces around it.
# bad
some_method(x, y, {a: 1, b: 2})
# good
some_method(x, y, a: 1, b: 2)
Example: EnforcedStyle: context_dependent
# The `context_dependent` style checks that the last parameter
# doesn't have braces around it, but requires braces if the
# second to last parameter is also a hash literal.
# bad
some_method(x, y, {a: 1, b: 2})
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
# good
some_method(x, y, a: 1, b: 2)
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
Favor a normal unless-statement over a modifier clause in a multiline statement. Open
xml.send('dc:subject') do
xml.cdata related.title
end unless [SystemSetting.blank_title, SystemSetting.no_public_version_title].include?(related.title)
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Favor a normal unless-statement over a modifier clause in a multiline statement. Open
xml.send('dc:subject') do
xml.cdata related.title
end unless [SystemSetting.blank_title, SystemSetting.no_public_version_title].include?(related.title)
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Use the return of the conditional for variable assignment and comparison. Open
if !passed_request.nil?
host = passed_request[:host]
else
host = request.host
end
- Exclude checks